Why are preprocessor macros evil and what are the alternatives?

前端 未结 8 2016
面向向阳花
面向向阳花 2020-11-22 02:46

I have always asked this but I have never received a really good answer; I think that almost any programmer before even writing the first \"Hello World\" had encountered a p

8条回答
  •  囚心锁ツ
    2020-11-22 03:01

    Preprocessor macros are not evil when they are used for intended purposes like:

    • Creating different releases of the same software using #ifdef type of constructs, for example the release of windows for different regions.
    • For defining code testing related values.

    Alternatives- One can use some sort of configuration files in ini,xml,json format for similar purposes. But using them will have run time effects on code which a preprocessor macro can avoid.

提交回复
热议问题