Sable / HorsePower

Optimizing database queries with array programming
18 stars 6 forks source link

A bug in C code #9

Closed wukefe closed 6 years ago

wukefe commented 7 years ago

Input

Filename: test_macro.cc

#include <stdio.h>

#define max(a,b) ((a)>(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))

#include <stdlib.h>

int main(){
    // test macro max/MAX
    printf("max(a,b)=%d\n",max(1,5));
    printf("MAX(a,b)=%d\n",MAX(1,5));
    return 0;
}

Testing

Environment

wukefe commented 6 years ago

If the line #include <stdlib.h> is moved upon the two macros, the compiler gcc-7 passes.

So probably there is a following macro inside stdlib.h for the compiler g++.

#ifdef max
#undef max
#endif