It is not possible to use a constant that has not previously been declared. But in this case, the constant was declared, but not trivially.
You will not find anywhere else (it should be in the header files), because these values are defined in the macro from command.h using point insertion (operator ## , which creates new identifiers, combining the old ones):
#define DEFINE_ACTION(_name) CMD_##_name, typedef enum cmd_type { CMD_TYPE_CODEC(DEFINE_ACTION) } cmd_type_t; #undef DEFINE_ACTION
so you never find CMD_ + your suffix. Then, using some magic (the macro name is probably overridden at some point), the following defines all the elements:
#define CMD_TYPE_CODEC(ACTION) \ ACTION( UNKNOWN ) \ ACTION( REQ_REDIS_DEL ) \ ACTION( REQ_REDIS_EXISTS ) \ ACTION( REQ_REDIS_EXPIRE ) \ ACTION( REQ_REDIS_EXPIREAT ) \ ACTION( REQ_REDIS_PEXPIRE ) \ ACTION( REQ_REDIS_PEXPIREAT ) \ ACTION( REQ_REDIS_PERSIST ) \ ACTION( REQ_REDIS_PTTL ) \ ACTION( REQ_REDIS_SORT ) \ ACTION( REQ_REDIS_TTL )
Such macros are very useful to avoid copy / paste, but this is hell when you try to find your way in code using grep .
source share