doon
doon

Reputation: 2361

`Is defining a macro via -D option ALWAYS equivalent to #define MACRO (except precedence)

I have a third party piece of code that works differently when I add a macro via Makefile e.g. -DMacro instead of doing #define MACRO in a top level header file (which as their documentation implies is included in ALL files).

I Googled if there are any differences in defining it in different ways but could not come up with much except Precedence of -D MACRO and #define MACRO.

I am wondering if I am missing anything about make documentation / C standards before I start debugging and determining the issue.

Thanks for any answers.

Upvotes: 1

Views: 218

Answers (1)

paxdiablo
paxdiablo

Reputation: 881563

Usually, it's exactly the same but neither make nor the ISO standard have anything to say about it. It's up to the compiler itself, some may not even have a -D option.

To make, it's just running the command (such as gcc) with whatever options it takes. ISO doesn't specify anything about how to run a compiler, just how the compiler (and the things it creates) behaves.

For gcc, the preprocessor options can be found here so it looks like it is identical to #define.

Upvotes: 2

Related Questions