Is max(a,b) defined in stdlib.h or not?

后端 未结 5 582
旧时难觅i
旧时难觅i 2021-02-04 00:55

I\'m using two computers, each with a different version of visual studio. On the visual studio 2008 computer my code compiles. On the visual 2010 computer my code doesn\'t compi

5条回答
  •  北恋
    北恋 (楼主)
    2021-02-04 01:34

    Protect it with an #ifndef.

    #ifndef max
        #define max(a,b) ((a) > (b) ? (a) : (b))
    #endif
    

    Keep in mind that the version above is not as safe as an inline function, e.g. max(a++,b--) will cause unxpected results.

提交回复
热议问题