How is the @encode compiler directive implemented in Objective-C applied?

Can someone explain how @encode works to extract data type elements present in a given object, structure or data type, into a type definition that will be used as a class descriptor to instantiate?

Or maybe a pointer to some resources for exploring the implementation of new preprocessor directives?

+6
c c-preprocessor objective-c implementation encode
source share
2 answers

The wording of the original question may have been unclear, and I think that my mention of a possible implementation using a preprocessor made the conversation move on to the intricacies of compilers, rather than the intended question.

Please refer to this question, which, I think, is much clearer regarding what I'm trying to learn: How to implement something similar to the Objective-C @encode () compiler directive in ANSI C?

+1
source share

The @encode directive @encode the provided type and generates a constant string based on this type. The encoding of all primitive C types (including signed and unsigned versions) and the Objective-C id and SEL types all have single-character encodings, which can be found in <objc/runtime.h> . More complex types, such as struct and arrays, have larger encodings.

Further information is available in the Objective-C Runtime Programming Guide [PDF].

+5
source share

All Articles