Annotation of coherent/a/usr/man/ALL/_23, revision 1.1.1.1

1.1       root        1: 
                      2: 
                      3: #                     Preprocessing Operator                    #
                      4: 
                      5: 
                      6: 
                      7: 
                      8: String-ize operator
                      9: 
                     10: 
                     11: The preprocessing  operator # can be  used within the replacement
                     12: list of  a function-like macro.  It and  its operand are replaced
                     13: by a  string literal, which  names the sequence  of preprocessing
                     14: tokens that replaces the operand throughout the macro.
                     15: 
                     16: For example, the consider the macro:
                     17: 
                     18: 
                     19:         #define display(x) show((long)(x), #x)
                     20: 
                     21: 
                     22: When the preprocessor reads the following line
                     23: 
                     24: 
                     25:         display(abs(-5));
                     26: 
                     27: 
                     28: it replaces it with the following:
                     29: 
                     30: 
                     31:         show((long)(abs(-5)), "abs(-5)");
                     32: 
                     33: 
                     34: Here, the  preprocessor replaced #x  with  a string  literal that
                     35: gives the sequence of token that replaces x.
                     36: 
                     37: The following rules apply to interpreting the # operator:
                     38: 
                     39: 11.  If a  sequence of  white-space  characters occurs  within the
                     40:    preprocessing tokens that replace the argument, it is replaced
                     41:    with one space character.
                     42: 
                     43: 22.  All  white-space  characters  that  occur  before  the  first
                     44:    preprocessing token and after the last preprocessing token are
                     45:    deleted.
                     46: 
                     47: 33.  The   original  spelling  of  the   preprocessing  tokens  is
                     48:    preserved.   This means  that you must  take care  to preserve
                     49:    certain characters: a  backslash `\' should be inserted before
                     50:    every  quotation mark  `"' that  marks  a string  literal, and
                     51:    before every backslash that introduces a character constant.
                     52: 
                     53: ***** Example *****
                     54: 
                     55: The  following  uses the  operator  # to  display  the result  of
                     56: several mathematics routines.
                     57: 
                     58: 
                     59: 
                     60: 
                     61: 
                     62: 
                     63: 
                     64: COHERENT Lexicon                                           Page 1
                     65: 
                     66: 
                     67: 
                     68: 
                     69: #                     Preprocessing Operator                    #
                     70: 
                     71: 
                     72: 
                     73: #include <errno.h>
                     74: #include <math.h>
                     75: #include <stdio.h>
                     76: 
                     77: 
                     78: 
                     79: void show(value, name)
                     80: double value, char *name;
                     81: {
                     82:         if (errno)
                     83:                 perror(name);
                     84:         else
                     85:                 printf("%10g %s\n", value, name);
                     86:         errno = 0;
                     87: }
                     88: 
                     89: 
                     90: 
                     91: #define display(x) show((double)(x), #x)
                     92: 
                     93: 
                     94: 
                     95: main()
                     96: {
                     97:         extern char *gets();
                     98:         double x;
                     99:         char string[64];
                    100: 
                    101: 
                    102: 
                    103:         for(;;) {
                    104:                 printf("Enter a number: ");
                    105:                 fflush(stdout);
                    106:                 if(gets(string) == NULL)
                    107:                         break;
                    108: 
                    109: 
                    110: 
                    111:                 x = atof(string);
                    112:                 display(x);
                    113:                 display(cos(x));
                    114:                 display(sin(x));
                    115:                 display(tan(x));
                    116:                 display(acos(cos(x)));
                    117:         }
                    118: }
                    119: 
                    120: 
                    121: ***** See Also *****
                    122: 
                    123: ##, #define, C preprocessor
                    124: 
                    125: 
                    126: 
                    127: 
                    128: 
                    129: 
                    130: COHERENT Lexicon                                           Page 2
                    131: 
                    132: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.