4 ms·
typeof is pretty smart. Since in C all types are known at compile-time, the compiler can put in there in whatever type typeof's parameter resolves to- even if i
by paulbaumgart 17y ago
typeof is pretty smart. Since in C all types are known at compile-time, the compiler can put in there in whatever type typeof's parameter resolves to- even if it's an expression.
As an example:
int main () {
typeof (1.0f + 10) a;
int * b = &a;
}
-----
$ g++ test.c
test.c: In function ‘int main()’:
test.c:3: error: cannot convert ‘float*’ to ‘int*’ in initialization
I'm using g++ because it actually spits out type information for incompatible pointers- probably something having to do with it being an error in C++ but valid in C (with a warning, at least in GCC).