If I'll tell you I want to implement the following code:
static const uint8_t jump_table[] =
{
/* ' ' */ 1, 0, 0, /* '#' */ 4,
0, /* '%' */ 14, 0, /* '\''*/ 6,
...
...
/* 't' */ 27, /* 'u' */ 16, 0, 0,
/* 'x' */ 18, 0, /* 'z' */ 13
};
#define LABEL(Name) do_##Name
#define NOT_IN_JUMP_RANGE(Ch) ((Ch) < ' ' || (Ch) > 'z')
#define CHAR_CLASS(Ch) (jump_table[(INT_T) (Ch) - ' '])
#define REF(Name) &&do_##Name
#define JUMP(ChExpr, table) \
do \
{ \
const void *ptr; \
spec = (ChExpr); \
ptr = NOT_IN_JUMP_RANGE (spec) ? REF (form_unknown) \
: table[CHAR_CLASS (spec)]; \
goto *ptr; \
} while (0)
#define TABLE \
/* Step 0: at the beginning. */ \
static JUMP_TABLE_TYPE step0_jumps[30] = \
{ \
REF (form_unknown), \
REF (flag_space), /* for ' ' */ \
REF (flag_plus), /* for '+' */ \
REF (flag_minus), /* for '-' */ \
... \
REF (flag_i18n), /* for 'I' */ \
};
With this usage example:
void usage_example_function(void)
{
do
{
TABLE;
/* Get current character in format string. */
JUMP (*++f, step0_jumps);
/* ' ' flag. */
LABEL (flag_space):
space = 1;
JUMP (*++f, step0_jumps);
...
...
} while (something)
}
You would tell me that it's unacceptable under any decent coding style standard and committing such code will most likely to do more harm than good.
Now, glibc implements vfprintf with far more macro abusing than this (code above taken from there), yet this code is a part of so many compiled programs and was tested so many times that it makes me fill that any today's (macro) coding standards lack justification.
Why is such a macro abusing is wrong? or alternatively, if such abusing is so wrong, why do we accept such libc implementation?