[[ blog 이사 과정에서 정확한 posting날짜가 분실됨. 년도와 분기 정도는 맞지 않을까? ]]
This is tip to define 'enum' that has quite lots of items and important information - ex thread id, event id, etc...
This is tip to define 'enum' that has quite lots of items and important information - ex thread id, event id, etc...
(*1)
// File : "main"
enum
{
enum01,
enum02,
...
}
...
This is not recommended.
How about using following way?
(*2)
// File : "enum.h "
DEF_ENUM(enum01)
DEF_ENUM(enum02)
...
------------------
// File : "main
#define DEF_ENUM(x) x,
enum
{
#include "enum.h"
}
#undef DEF_ENUM
Why this way is better? Let's assume that you want to print 'enum' values.
In (*1) case, only number value can be printed. But in (*2) case, even enum name - string - can be easily printed by following way.
// File : "Enum_str.c"
#define DEF_ENUM(x) #x,
static const char* enum_str[] =
{
#include "enum.h"
};
...
printf("%s", enum_str[enum_id]);
It is good, isn't it?
Except for this, you can find other lots of useful ways by using macro.
'Language > C&C++' 카테고리의 다른 글
| [C/C++] Remind! Multiple-Inheritance of same-named-method from two classes. (0) | 2007.03.18 |
|---|---|
| [C/C++] Remind! '>>' extends sign bit (0) | 2007.01.11 |
| [C/C++][Tip] Macro... (0) | 2006.11.17 |
| [C/C++] Unrolling loop. (0) | 2006.11.10 |
| [C/C++] make constant to be l-value. (0) | 2006.07.06 |