-
Notifications
You must be signed in to change notification settings - Fork 0
/
X-Macro.cpp
45 lines (32 loc) · 861 Bytes
/
X-Macro.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// X-Macro.cpp : Defines the entry point for the console application.
//
#include <stdio.h>
#include <tchar.h>
///////////////////////////////////////////////
// X-Macro Expansion - Enum
enum RC_CODES {
#define X(a) e##a,
#include "x-macro.h"
#undef X
};
///////////////////////////////////////////////
// X-Macro Expansion - String
static char *ErrString[] = {
#define X(a) #a,
#include "x-macro.h"
#undef X
};
/////////////////////////////////////////////////
#define ARRAY_SIZE(a) (sizeof(a)/sizeof(*a))
int _tmain(int argc, _TCHAR* argv[])
{
int n = ARRAY_SIZE(ErrString);
// print all enums
for (int i = 0; i < n; i++)
{
printf("id %d, str \"%s\"\n", i, ErrString[i]);
}
// print individual enums
printf(" eFailed is \"%s\"\n", ErrString[eFAILED]);
return 0;
}