If you intend to use GNU style variable argument
macros in HP C, note that you can make the concatenation operator
## prevent syntax errors from occurring when the variable argument
comes in as empty (the null string).
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
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, donot expect the same behavior in HP aC++. For the example:
for(int i = 0; i < j; i ++) int i;
Note the lack of a new block opening for the for statement. The C++ compiler accepts this form, with warnings,
but the C compiler does not. The difference in the way the stack
is handled causes the difference in behavior.
Previously, the C compiler did not emit the source file information
for the global typedefs. To correct this, use -y option along with -g when debug info is generated. You can generate debug
information by compiling with +objdebug.