All the talk about macros this week inspired me to share this macro that Lance Robinson came across while maintaining a C-based system at his company. What I really appreciate about this code, well, aside from the fact that it's built into ctype.h and, aside from the fact that it has nests twenty-six ternary operators, is its very subtle bug ... can you spot it?

// Macro to normalize table names
// (all of them will be stored in upper case )
#define TO_UPPER( x )(               \
     ( 'a' == ( x ) ) ? 'A' :        \
     ( 'b' == ( x ) ) ? 'B' :        \
     ( 'c' == ( x ) ) ? 'C' :        \
     ( 'd' == ( x ) ) ? 'D' :        \
     ( 'e' == ( x ) ) ? 'E' :        \
     ( 'f' == ( x ) ) ? 'F' :        \
     ( 'g' == ( x ) ) ? 'G' :        \
     ( 'h' == ( x ) ) ? 'H' :        \
     ( 'i' == ( x ) ) ? 'I' :        \
     ( 'j' == ( x ) ) ? 'J' :        \
     ( 'k' == ( x ) ) ? 'K' :        \
     ( 'l' == ( x ) ) ? 'L' :        \
     ( 'm' == ( x ) ) ? 'M' :        \
     ( 'n' == ( x ) ) ? 'N' :        \
     ( 'o' == ( x ) ) ? 'O' :        \
     ( 'p' == ( x ) ) ? 'P' :        \
     ( 'q' == ( x ) ) ? 'Q' :        \
     ( 'r' == ( x ) ) ? 'R' :        \
     ( 's' == ( x ) ) ? 'S' :        \
     ( 't' == ( x ) ) ? 'T' :        \
     ( 'u' == ( x ) ) ? 'U' :        \
     ( 'v' == ( x ) ) ? 'V' :        \
     ( 'w' == ( x ) ) ? 'W' :        \
     ( 'x' == ( x ) ) ? 'X' :        \
     ( 'y' == ( x ) ) ? 'Y' :        \
     ( 'Z' == ( x ) ) ? 'Z' :  ( x ) \
    )

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!