Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Moved a Wiki link out of a code block.

...

Code Block
enum Color { Color_Red, Color_Green, Color_Blue };
static const struct {
  enum Color  color;
  const char *name;
} colors[] = {
#define COLOR(color)   { Color_ ## color, #color }
  COLOR(Red), COLOR(Green), COLOR(Blue)
};

See [

calculates only one of the two expressions depending on the selector's value. See PRE05-C.

...

Understand

...

macro

...

replacement

...

when

...

concatenating

...

tokens

...

or

...

performing

...

stringification

...

for

...

more

...

information

...

calculates only one of the two expressions depending on the selector's value.

PRE00-EX3: Macros can be used to yield a compile-time constant. This is not always possible using inline functions, as shown by the following example:

...