HP C B.11.11.16 Release Notes
HP C/ANSI C Release Notes
Problem Description and Fixes
Chapter 128
However, you can also insert whitespace to the left of the left operand of ## to more
accurately specify the intended left operand.
For example, if you use
#define foo(f, s...) printf(f, s)
Then the macro call
foo(“Hello world.\n”);
results in the expansion
printf(“Hello world.\n”,);
(Note the comma ",") causing a syntax error.
GNU provides the following workaround for this kind of a situation. If you use:
#define foo(f, s...) printf(f, ## s)
If the variable parameter s is non-null, and if you use:
foo("%s %d\n", "Cycles", "1024");
The result is:
printf("%s %d\n", "Cycles", "1024");
as the expansion as you would expect.
However, if s is null, this erases the comma to the left of the ## in the macro definition
and resulting expansion is:
printf("Hello world.\n");
Note that the comma is removed.
In order to get the same behavior in HP C, you must insert a space to the left of the
comma to make it clear to the preprocessor that the comma is the left operand of the ##
operator. Thus your definition for the macro foo is:
#define foo(f, s...) printf(f , ## s)
^
(Note the space to the left of the ## operator in the macro definition.)
If the space is not inserted, the left operand of the ## operator is understood to be:
printf(f ,.
Because there is no parameter by that name for foo, it is erased.
When specifying declarations within code in the HP C/ANSI C compiler, do