HPlogo HP C/HP-UX Release Notes for HP-UX 11.01: HP 9000 Computers > Chapter 1 New and Changed Features

C9X standard macros

» 

Technical documentation

Complete book in PDF

 » Table of Contents

The C9X standard-compliant version of "variadic" or variable argument (varargs) macro notation has been added to the HP ANSI C compiler. The notation for C9X standard and for the popular GNU version of varargs is very similar.

If you have coded your macros to the GNU standards, you can expect GNU-style behavior using the HP ANSI C compiler. If you have coded your macros to C9X standards, you can expect C9X-style behavior.

IMPORTANT: Differences in HP C implementations of GNU and C9X macros are noted in Chapter 4 “Problem Descriptions and Fixes ”.

Usage differences

In the HP ANSI C compiler, if there is an ellipsis (...) in the macro definition's argument list, then the trailing arguments (including any separating comma and preprocessing tokens) are merged to form a single item: these are variable arguments. The trailing arguments (including separating commas) are combined and considered as a single argument so that the number of arguments is more than the number of parameters in the macro definition, excluding the ellipsis (...).

There are minor usage differences between how C9X and GNU specify variable argument macros are defined:

Table 1-1 How C9X and GNU define a variable argument macro

C9X

GNU

#define foo(f, ...) printf (f, __VA_ARGS__)#define foo(f, s...) printf (f, s)

 

  • In the GNU style, the name of the variable parameter s precedes the ellipsis in the parameter list.

  • In the C9X standard, the identifier __VA_ARGS__ refers to the variable arguments.

  • The identifier __VA_ARGS__ can only occur only in the replacement-list of a function-like macro that uses the ellipsis notation in the arguments.

Variable names

Variable names are also handled slightly different by C9X and GNU.

Table 1-2 How C9X and GNU refer to varargs in macro replacement text

C9X

GNU

Specified by the identifier __VA_ARGS__.Name appears in the replacement text.

 

For example:

  • __VA_ARGS__ in the replacement text indicates a variable name in the following C9X-style code:

    printf(f, __VA_ARGS__)

  • s in the replacement text indicates a variable name in the following GNU-style code:

    printf(f, s)

© Hewlett-Packard Development Company, L.P.