3 ms·
Where's the problem? ~ $ cat sizeofmacro.c #include <stdio.h> #define pintsize(T) printf("sizeof(%s) is %zu. Big or small? You decide.\n", #T, sizeof(T)
by yorwba 3y ago
Where's the problem?
~ $ cat sizeofmacro.c
#include <stdio.h>
#define pintsize(T) printf("sizeof(%s) is %zu. Big or small? You decide.\n", #T, sizeof(T))
int main(int argc, char **argv) {
pintsize(int);
pintsize(argv);
return 0;
}
~ $ gcc sizeofmacro.c && ./a.out
sizeof(int) is 4. Big or small? You decide.
sizeof(argv) is 8. Big or small? You decide.
- blibble 3y agothe preprocessor isn't evaluating it, it's just pasting the tokens in the preprocessor doesn't know anything about structs or types
- diydsp 3y agoI was curious, too. Looked it up. Still don't understand tho. >The sizeof in C is an operator, and all operators have been implemented at compiler level; therefore, you cannot implement sizeof operator in standard C as a macro or function. You can do a trick to get the size of a variable by pointer arithmetic.