News for hackers. Stuff that matters.
Re:Oops! We Automated Bullshit by yorwba on Friday November 17, 2023 @09:05AM (#38303698)
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.
Re:Oops! We Automated Bullshit by blibble on Friday November 17, 2023 @09:34AM (#38304138)
the preprocessor isn't evaluating it, it's just pasting the tokens in

the preprocessor doesn't know anything about structs or types

Re:Oops! We Automated Bullshit by diydsp on Friday November 17, 2023 @09:49AM (#38304343)
I 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.