Multiple values in MACRO

57 Views Asked by At

Could I find help dissecting this macro. The syntax seems familiar yet strange.

#define   MACRO_NAME   [0] = value0, [1] = value1, [2] = value3

It's a macro I came across while maintaining code. Any help would be much appreciated.

1

There are 1 best solutions below

2
nielsen On

This is a simple macro. The preprocessor will replace any occurrence of MACRO_NAME with [0] = value0, [1] = value1, [2] = value3.

Thus, the macro seems to have a purpose in designated initialization of an array, however, its usefulness is difficult to imagine. It requires that value0, value1, and value3 are defined (either as variables or macros) at the place where MACRO_NAME is expanded.

E.g.:

   #define value0 12
   #define value1 17
   int value3 = 24;
   int a[4] = {MACRO_NAME, [3] = 100};
   int b[5] = {MACRO_NAME, [3] = 200, [4] = 11};