Is typeof in C, really an operator?
I'm thinking because there is no polymorphism in C, that there is nothing to do at run-time. That is, the answer to typeof is known at compile-time. (I can't think of a use of typeof that would not be known at compile time.) So it appears to be more of a compile-time directive, than an operator.
Does typeof use any (processor) run-time (in GCC)?
It's not exactly an operator, rather a keyword. And no, it doesn't do any runtime-magic.
It's a GNU extension. In a nutshell it's a convenient way to declare an object having the same type as another. For example:
int x; /* Plain old int variable. */
typeof(x) y; /* Same type as x. Plain old int variable. */
It works entirely at compile-time and it's primarily used in macros. One famous example of macro relying on typeof
is container_of
.
It is a C extension from the GCC compiler , see http://gcc.gnu.org/onlinedocs/gcc/Typeof.html
Source: Stackoverflow.com