COHERENT manpages

This page displays the COHERENT manpage for ## [Token-pasting operator].

List of available manpages
Index


## -- Preprocessing Operator

Token-pasting operator

The preprocessing operator ## can be used in both object-like and function-
like macros.  When used  immediately before or immediately after an element
in the  macro's replacement list,  ## joins the  corresponding preprocessor
token with its neighbor.  This is sometimes called ``token pasting''.

As an example of token pasting, consider the macro:

    #define printvar(number) printf("%s\n", variable ## number)

When the preprocessor reads the following line

    printvar(5);

it substitutes the following code for it:

    printf("%s\n", variable5);

The preprocessor throws  away all white space both before  and after the ##
operator.  This gives you an easy way to print any one of a set of strings.

## must not be used as  the first or last entry in a replacement list.  All
instances of the ##  operator are resolved before further macro replacement
is performed.

For more information on object-like and function-like macros, see #define.

See Also

#
#define,
C preprocessor
ANSI Standard, §6.8.3.3

Notes

Some C implementations allow token  pasting by using an empty comment.  For
example:

    variable/**/number

The COHERENT C compiler does not recognize this ``trick'' because it is not
consistent with  the Kernighan &  Ritchie standard for  C, which states
that a comment  is white space and therefore is  a token separator.  In any
event, token pasting should always be performed with ##.

The  ##  operator  may be  used  only  within  the  replacement text  of  a
preprocessor macro definition.

The order of evaluation of multiple ## operators is unspecified.