krupa n
krupa n

Reputation: 11

How to overwrite a macro definition using compiler options

I want to redefine a macro, without modifying the header or source files.

For example: #define macro_1 Present -- Is what actually defined in the header file

For one set of execution I need this macro to be same as it is , but for another set of execution I need the macro to be redefined to value 'Absent' This should be done without changing the header file. Am using the ghs compliler.

I tried undef option but its not effectively working

Upvotes: 1

Views: 616

Answers (2)

pts
pts

Reputation: 87441

What you are asking is not possible with most compilers if the code doesn't already contain #ifndef macro_1 or similar.

If it does, then see the answer by.Some programmer dude.

Upvotes: 0

Some programmer dude
Some programmer dude

Reputation: 409482

For GCC or Clang, the option to define a macro on the command line is -D. As in -D macro_1=\"Absent\".

You need to use conditional-compilation in the header file though:

#ifndef macro_1
# define macro_1 "Present"
#endif

Otherwise you will get macro redefinition errors.

Upvotes: 1

Related Questions