Question

Can anyone explain how @encode works to extract the datatype elements present in a given object, struct, or datatype into a type definition to be used as a class descriptor for instantiation?

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

Was it helpful?

Solution 2

The phrasing of the original question may have been unclear and I think that my mentioning of a possible implementation involving the preprocessor caused the conversation to turn toward the subtleties of how compilers work rather than the intended question.

Please reference this question, which I believe is much more clear as to what I'm trying to learn: How would I implement something similar to the Objective-C @encode() compiler directive in ANSI C?

OTHER TIPS

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

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top