[Solved] Why preprocessor doesn’t expand type defined later in the code


The preprocessor just performs a single pass through the file, expanding macros as it goes, and adding macros to its list when it encounters the #define. When it gets to the line

typedef BLA_Str blaInstance

it doesn’t yet know about the BLA_Str macro, so it leaves it unchanged in the output.

You shold generally put all the #define lines at the beginning, so they’ll affect everything in the rest of the file.

You can find a reasonable summary of how the C preprocessor works in The C Book. It explains:

There are two ways of defining macros, one of which looks like a function and one which does not. Here is an example of each:

   #define FMAC(a,b) a here, then b
   #define NONFMAC some text here

Both definitions define a macro and some replacement text, which will be used to replace later occurrences of the macro name in the rest of the program.

If a macro expands into another macro, this is handled with rescanning:

Once the processing described above has occurred, the replacement text plus the following tokens of the source file is rescanned, looking for more macro names to replace. The one exception is that, within a macro’s replacement text, the name of the macro itself is not expanded.

3

solved Why preprocessor doesn’t expand type defined later in the code