# -- Preprocessing Operator

String-ize operator

The preprocessing operator  # can be used within the  replacement list of a
function-like macro.  It and its  operand are replaced by a string literal,
which names the sequence  of preprocessing tokens that replaces the operand
throughout the macro.

For example, the consider the macro:

    #define display(x) show((long)(x), #x)

When the preprocessor reads the following line

    display(abs(-5));

it replaces it with the following:

    show((long)(abs(-5)), "abs(-5)");

Here, the  preprocessor replaced #xx  with  a string literal  that gives the
sequence of token that replaces xx.

The following rules apply to interpreting the # operator:

11. If a sequence  of white-space characters occurs within the preprocessing
   tokens  that  replace  the  argument,  it  is replaced  with  one  space
   character.

22. All  white-space characters  that occur  before the  first preprocessing
   token and after the last preprocessing token are deleted.

33. The original  spelling of the  preprocessing tokens is  preserved.  This
   means  that  you  must  take  care  to preserve  certain  characters:  a
   backslash `\'  should be inserted  before every quotation  mark `"' that
   marks a  string literal,  and before  every backslash that  introduces a
   character constant.

_E_x_a_m_p_l_e
The  following  uses  the operator  #  to  display  the  result of  several
mathematics routines.

#include <errno.h>
#include <math.h>
#include <stdio.h>

void show(value, name)
double value, char *name;
{
    if (errno)
        perror(name);
    else
        printf("%10g %s\n", value, name);
    errno = 0;
}

#define display(x) show((double)(x), #x)

main()
{
    extern char *gets();
    double x;
    char string[64];

    for(;;) {
        printf("Enter a number: ");
        fflush(stdout);
        if(gets(string) == NULL)
            break;

        x = atof(string);
        display(x);
        display(cos(x));
        display(sin(x));
        display(tan(x));
        display(acos(cos(x)));
    }
}

_S_e_e _A_l_s_o
##, #ddeeffiinnee, CC pprreepprroocceessssoorr
ANSI Standard, section 6.8.3.2
