codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
#include <stdio.h> // this goes to shared header #define DECLARE_STRING_ENUM_FST(name, value) name #define DECLARE_STRING_ENUM_SND(name, value) value #define DECLARE_STRING_ENUM(name, macro) \ typedef enum name { macro(DECLARE_STRING_ENUM_FST) } name; \ static const char* name##_table[] = { macro(DECLARE_STRING_ENUM_SND) }; \ // this is a usage example #define MSG_ENUM_(X) \ X(str_first, "This is the first message."), \ X(str_second, "This is the second message.") DECLARE_STRING_ENUM(str_id_t, MSG_ENUM_) int main() { printf("%s\n", str_id_t_table[str_first]); printf("%s\n", str_id_t_table[str_second]); return 0; }
Private
[
?
]
Run code
Submit