Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22014

Variadic macro expansion's going wrong

$
0
0

Consider the following code

#define COMB(F, ...) F(__VA_ARGS__)


#define ADD(X, Y) (X + Y)


int foo() {
    return COMB(ADD, 1, 2);
}

I have done some experiments on Godbolt. Microsoft VS v19.22 (with /E flag) fails at preprocessing the macro's. It gives the following error

int foo() {

    return (1, 2 + );

}

example.cpp

<source>(8): warning C4003: not enough arguments for function-like macro invocation 'ADD'

GCC (with -E flag) simply outputs as expected

int foo() {
    return (1 + 2);
}

I took a look at the C99 standard. But I am still not sure which compiler is doing it right?

I hope somebody can help me with clarifying this.


Viewing all articles
Browse latest Browse all 22014

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>