|< 1 2 >| | 13 Einträge, 2 Seiten |
1
2
3
4
#define WARN_IF(EXP) \
do { if (EXP) \
fprintf (stderr, "Warning: " #EXP "\n"); } \
while (0)
1
2
3
4
5
6
7
8
#define MAX_RECURSIONS 40
...
if(rec > MAX_RECURSIONS){
fprintf(stderr, "Too many recursions (" #MAX_RECURSIONS ")\n");
exit(1);
}
1
2
3
4
5
6
7
#define ERROR_RECURSION(n) \
do { if (n) \
fprintf (stderr, "Too many recursions (" #n ")\n"); \
exit(0); \
while (0)
if(rec > MAX_RECURSIONS) ERROR_RECURSION(MAX_RECURSIONS);
#define TOSTRING(x) #x
1
2
3
4
5
6
7
#define ERROR_RECURSION(n) \
do { if (n) \
fprintf (stderr, "Too many recursions (" #n ")\n"); \
exit(0); \
while (0)
if(rec > MAX_RECURSIONS) ERROR_RECURSION(MAX_RECURSIONS);
1
2
3
4
5
6
7
#define ERROR_RECURSION(n) \
do { if (n) \
fprintf (stderr, "Too many recursions (" #n ")\n"); \
exit(0);} \
while (0)
if(rec > MAX_RECURSIONS) ERROR_RECURSION(MAX_RECURSIONS);
QuoteIf you want to stringify the result of expansion of a macro argument,
you have to use two levels of macros.
#define xstr(s) str(s)
#define str(s) #s
#define foo 4
str (foo)
==> "foo"
xstr (foo)
==> xstr (4)
==> str (4)
==> "4"
1
2
3
4
5
#define ERROR_RECURSION(n) \
do { if (n) \
fprintf (stderr, "Too many recursions (" str(n) ")\n"); \
exit(0);} \
while (0)
|< 1 2 >| | 13 Einträge, 2 Seiten |