Changing a macro at runtime in C

后端 未结 5 1435
野趣味
野趣味 2020-11-30 12:29

I have a macro defined. But I need to change this value at run time depending on a condition. How can I implement this?

5条回答
  •  心在旅途
    2020-11-30 12:48

    You can't.

    As a macro is resolved by the preprocessor before the compilation itself, its content is directly copied where you use it.

    You can still use parameters to insert a conditional statement depending on what you want, or use a call-scope accessible variable.

    If you want to change a single value, better use global scope variable, even if such behavior is discouraged. (as the intensive use of macro)

提交回复
热议问题