4

I am trying to use #ifdef preprocessive directive in my program. I want to define this macro at run time (would be better if I define this value in another configuration file so that I can define it or undefine it any time without compiling) and so I don't want to define it in make file.

I searched a lot about this in Google. But I am not able to get the exact information which I wanted.

Is there any way to define it in run time.? If yes, kindly suggest.

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
user3256147
  • 378
  • 2
  • 9
  • 3
    "Preprocessor" means it runs before the source code is processed by the compiler. So if I understand correctly what you want it is a completely nonsense. Like running program before it is programmed and compiled? Not possible. – Al Kepp Apr 23 '14 at 01:18
  • Possible duplicate of [Changing a macro at runtime in C](https://stackoverflow.com/questions/7572872/changing-a-macro-at-runtime-in-c) – hola Sep 11 '17 at 17:23

1 Answers1

6

No, #ifdef and other # directives are used during compilation only, and in fact even before the compilation itself by an (internal) tool called the preprocessor.

If you want run-time configurability, you will need to use plain if statements etc. Or make two builds of the same program etc.

Yirkha
  • 12,737
  • 5
  • 38
  • 53