typeof operator in C

Doug picture Doug · Aug 22, 2012 · Viewed 127.7k times · Source

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)?

Answer

Jens Gustedt picture Jens Gustedt · Aug 23, 2012

Since typeof is a compiler extension, there is not really a definition for it, but in the tradition of C it would be an operator, e.g sizeof and _Alignof are also seen as an operators.

And you are mistaken, C has dynamic types that are only determined at run time: variable modified (VM) types.

size_t n = strtoull(argv[1], 0, 0);
double A[n][n];
typeof(A) B;

can only be determined at run time.