Why are preprocessor macros evil and what are the alternatives?

前端 未结 8 2212
面向向阳花
面向向阳花 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 02:50

    I don't think that there is anything wrong with using preprocessor definitions or macros as you call them.

    They are a (meta) language concept found in c/c++ and like any other tool they can make your life easier if you know what you're doing. The trouble with macros is that they are processed before your c/c++ code and generate new code that can be faulty and cause compiler errors which are all but obvious. On the bright side they can help you keep your code clean and save you a lot of typing if used properly, so it comes down to personal preference.

提交回复
热议问题