Playing with __ attributes__ (V)




@interface MyRootObject


Used to declare a root class. In Objective-C, there is a default compilation flag-Wobjc-root-class, that is, it is not allowed to declare one that does not inherit fromNSObjectofclass。 Use this attribute to declare a custom root class.
About root class, Apple’s document stamphere

As for the usefulness of my own root class, I’m not sure. What you can know is that because it does not inherit from nsobject, it means that there is no-alloc,-initAnd other methods. It seems impossible to instantiate.



void foo() __attribute__((naked));


That’s what llvm said

This attribute disables prologue / epilogue emission for the function. This can have very system-specific consequences.

When the function is called / returned, there will be some extra work, that is, a series of operations on the stackReference 1 2 3。 This attribute will make the compiler do nothing to this function, so it is called naked:). It will be used at the beginning of some low-level functions, such as implementing interrupt functions or directly implementing functions with ASM. For example:

void foo() __attribute__((naked)) {
    __asm__ __volatile__ ("nop\n");


Come to an end. Four articles have been written in the front, and there are not many things in the last one. There are not many interesting and simple attributes found later. Specifically, you can only read clang’s documents carefully.

Other references
clang language extensions

The original work was written in segment faultlink