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?
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 struct
s and arrays have larger encodings.
More information is available in the Objective-C Runtime Programming Guide [PDF].
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With