Why is the 'max' macro defined like this in C?

后端 未结 4 501
故里飘歌
故里飘歌 2021-01-05 02:17
 #define max(a,b) \\
   ({ typeof (a) _a = (a); \\
       typeof (b) _b = (b); \\
     _a > _b ? _a : _b; })

Why not simply (a>b ? a :

4条回答
  •  别那么骄傲
    2021-01-05 03:06

    Another way to determine max (at least for positive numbers)

    #define MAX(a,b) sizeof(union x { char ca[a]; char cb[b];})
    

    As a and b are accessed only once, MAX(a++,b++) gives the correct result.

提交回复
热议问题