What are C macros useful for?

前端 未结 18 2111
-上瘾入骨i
-上瘾入骨i 2020-11-28 19:45

I have written a little bit of C, and I can read it well enough to get a general idea of what it is doing, but every time I have encountered a macro it has thrown me complet

18条回答
  •  误落风尘
    2020-11-28 20:03

    One of the obvious reasons is that by using a macro, the code will be expanded at compile time, and you get a pseudo function-call without the call overhead.

    Otherwise, you can also use it for symbolic constants, so that you don't have to edit the same value in several places to change one small thing.

提交回复
热议问题