Typechecking macro arguments in C
Posted
by
Rocketmagnet
on Stack Overflow
See other posts from Stack Overflow
or by Rocketmagnet
Published on 2011-01-17T11:41:12Z
Indexed on
2011/01/17
12:53 UTC
Read the original article
Hit count: 154
Hi all,
Is is possible to typecheck arguments to a #define macro? For example:
typedef enum
{
REG16_A,
REG16_B,
REG16_C
}REG16;
#define read_16(reg16) read_register_16u(reg16); \
assert(typeof(reg16)==typeof(REG16));
The above code doesn't seem to work. What am I doing wrong?
BTW, I am using gcc, and I can guarantee that I will always be using gcc in this project. The code does not need to be portable.
© Stack Overflow or respective owner