Consider following program:
#include <iostream>
#define add(s,m,a) ( s + m + a + 0 )
int main()
{
std::cout<<add(3,4,5)<<'\n';
std::cout<<add(15,30,)<<'\n';
std::cout<<add(10, , 33)<<'\n';
std::cout<<add(10,,)<<'\n';
std::cout<<add(,,)<<'\n';
}
My compiler gcc 4.8.1 gives following warnings:
6 23 [Warning] invoking macro add argument 3: empty macro arguments are undefined in ISO C90 and ISO C++98 [enabled by default]
7 25 [Warning] invoking macro add argument 2: empty macro arguments are undefined in ISO C90 and ISO C++98 [enabled by default]
8 21 [Warning] invoking macro add argument 2: empty macro arguments are undefined in ISO C90 and ISO C++98 [enabled by default]
8 21 [Warning] invoking macro add argument 3: empty macro arguments are undefined in ISO C90 and ISO C++98 [enabled by default]
9 19 [Warning] invoking macro add argument 1: empty macro arguments are undefined in ISO C90 and ISO C++98 [enabled by default]
9 19 [Warning] invoking macro add argument 2: empty macro arguments are undefined in ISO C90 and ISO C++98 [enabled by default]
9 19 [Warning] invoking macro add argument 3: empty macro arguments are undefined in ISO C90 and ISO C++98 [enabled by default]
I know that C++ does not support empty preprocessor function macros arguments. But C99 allows preprocessor function macros to be specified with empty (missing) arguments.
(This feature is likely to be provided as an extension by many C++ compilers like g++ in above case). Is the behaviour of program indeed undefined as per C89 & C++ standard?
The C89/C90 and the C++98 standards simply did not define how empty macro arguments should be handled. As a result, the behaviour was undefined by omission, and a preprocessing-time warning or error message is a reasonable result of that.
C99, as you noted, was the first C standard to allow it, but worth mentioning too is that C++11 adopted the C99 wording. So no, it's no longer undefined behaviour in C++ to have empty macro arguments.