What are C macros useful for?

前端 未结 18 2079
-上瘾入骨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:11

    While I'm not a big fan of macros and don't tend to write much C anymore, based on my current tasking, something like this (which could obviously have some side-effects) is convenient:

    #define MIN(X, Y)  ((X) < (Y) ? (X) : (Y))
    

    Now I haven't written anything like that in years, but 'functions' like that were all over code that I maintained earlier in my career. I guess the expansion could be considered convenient.

提交回复
热议问题