Bug no macro definition of a function max

#incldue<stdio.h>
#define max(a,b) a>b? a:b

int main(){
	int a = 7;
	printf("%d\n", max(2,3));
	printf("%d\n", 5 + max(2,3));
	printf("%d\n", max(2, max(3, 4)));
	printf("%d\n", max(2, 3>4? 3:4));
	printf("%d\n", max(a++, 6));
}

However, values of not obtained, do not believe you try
given below max of the function code is not bug

#include<stdio.h>
#define MAX(a,b) ({\
    __typeof(a) __a = (a);\
    __typeof(b) __b = (b);\
    __a > __b ? __a : __b;\
})
#define P(func){\
    printf("%s = %d\n", #func, func);\
}

int main(){

    int a = 7;
    P(MAX(2, 3));
    P(5 + MAX(2, 3));
    P(MAX(2, MAX(3, 4)));
    P(MAX(2, 3>4? 3:4));
    P(MAX(a++, 6));
    return 0;#include<stdio.h>
#define MAX(a,b) ({\
    __typeof(a) __a = (a);\
    __typeof(b) __b = (b);\
    __a > __b ? __a : __b;\
})
#define P(func){\
    printf("%s = %d\n", #func, func);\
}

int main(){

    int a = 7;
    P(MAX(2, 3));
    P(5 + MAX(2, 3));
    P(MAX(2, MAX(3, 4)));
    P(MAX(2, 3>4? 3:4));
    P(MAX(a++, 6));

    return 0;
}
Published 48 original articles · won praise 5 · Views 775

Guess you like

Origin blog.csdn.net/weixin_43899266/article/details/103514563