fork download
  1. #include <stdio.h>
  2.  
  3. // ここで定数を定義する
  4. #define LIST \
  5. DEF(hoge, 1.0f), \
  6. DEF(gufa, 2.0f), \
  7. DEF(piyo, 3.0f)
  8.  
  9. // enumの生成
  10. #undef DEF
  11. #define DEF(a, b) a
  12. enum EnumHoge { LIST };
  13.  
  14. // 構造体の生成
  15. #undef DEF
  16. #define DEF(a, b) {a, b, #a}
  17. struct HogeHoge {
  18. EnumHoge id;
  19. float value;
  20. const char* name;
  21. } const table[] = { LIST };
  22.  
  23. int main(int ac, char*av []) {
  24. for (size_t n = 0; n < sizeof(table)/sizeof(HogeHoge); ++n) {
  25. printf("table[%d] = id:%d value:%f name='%s'\n", n, table[n].id, table[n].value, table[n].name);
  26. }
  27. }
  28.  
  29.  
  30.  
  31.  
Success #stdin #stdout 0s 2896KB
stdin
Standard input is empty
stdout
table[0] = id:0 value:1.000000 name='hoge'
table[1] = id:1 value:2.000000 name='gufa'
table[2] = id:2 value:3.000000 name='piyo'