fork(2) download
  1. #include <stdio.h>
  2. #include <iostream>
  3. #include <vector>
  4. #include <string.h>
  5.  
  6. #define MACRO_GET_1(str, i) \
  7.   (sizeof(str) > (i) ? str[(i)] : 0)
  8.  
  9. #define MACRO_GET_4(str, i) \
  10.   MACRO_GET_1(str, i+0), \
  11.   MACRO_GET_1(str, i+1), \
  12.   MACRO_GET_1(str, i+2), \
  13.   MACRO_GET_1(str, i+3)
  14.  
  15. #define MACRO_GET_STR(str) MACRO_GET_4(str, 0)
  16.  
  17. struct mystruct {
  18. char foo[4];
  19. };
  20.  
  21. int main() {
  22. mystruct obj{ MACRO_GET_STR("abcd") };
  23. const char* str = "abcd";
  24. std::cout << memcmp(obj.foo, str, 4); // 0
  25.  
  26. return 0;
  27. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
Standard output is empty