-qcpluscmt

C only

Description

Use this option if you want C++ comments to be recognized in C source files.

Syntax

Read syntax diagramSkip visual syntax diagram>>- -q--+-nocpluscmt-+-----------------------------------------><
        '-cpluscmt---'

Default

The default setting varies:

Notes

The __C99_CPLUSCMT compiler macro is defined when cpluscmt is selected.

The character sequence // begins a C++ comment, except within a header name, a character constant, a string literal, or a comment. Comments do not nest, and macro replacement is not performed within comments. The following character sequences are ignored within a C++ comment:

C++ comments have the form //text. The two slashes (//) in the character sequence must be adjacent with nothing between them. Everything to the right of them until the end of the logical source line, as indicated by a new-line character, is treated as a comment. The // delimiter can be located at any position within a line.

// comments are not part of C89. The result of the following valid C89 program will be incorrect if -qcpluscmt is specified:

main() {
  int i = 2;
  printf("%i\n", i //* 2 */
                 + 1);
}
The correct answer is 2 (2 divided by 1). When -qcpluscmt is specified, the result is 3 (2 plus 1).

The preprocessor handles all comments in the following ways:

A comment can span multiple physical source lines if they are joined into one logical source line through use of the backslash (\) character. You can represent the backslash character by a trigraph (??/).

Examples

  1. Example of C++ Comments

    The following examples show the use of C++ comments:

    // A comment that spans two \
       physical source lines
     
    // A comment that spans two ??/
       physical source lines
  2. Preprocessor Output Example 1

    For the following source code fragment:

    int a;
    int b;  // A comment that spans two \
               physical source lines
    int c;
            // This is a C++ comment
    int d;

    The output for the -P option is:

    int a;
    int b;
    int c;
     
    int d;

    The C89 mode output for the -P -C options is:

    int a;
    int b;  // A comment that spans two    physical source lines
    int c;
            // This is a C++ comment
    int d;

    The output for the -E option is:

    int a;
    int b;
     
    int c;
     
    int d;

    The C89 mode output for the -E -C options is:

    #line 1 "fred.c"
    int a;
    int b;  // a comment that spans two \
               physical source lines
    int c;
            // This is a C++ comment
    int d;

    Extended mode output for the -P -C options or -E -C options is:

    int a;
    int b;  // A comment that spans two \
               physical source lines
    int c;
            // This is a C++ comment
    int d;
  3. Preprocessor Output Example 2 - Directive Line

    For the following source code fragment:

    int a;
    #define mm 1   // This is a C++ comment on which spans two \
                      physical source lines
    int b;
                   // This is a C++ comment
    int c;

    The output for the -P option is:

    int a;
    int b;
     
    int c;

    The output for the -P -C options:

    int a;
    int b;
                   // This is a C++ comment
    int c;

    The output for the -E option is:

    #line 1 "fred.c"
    int a;
    #line 4
    int b;
     
    int c;

    The output for the -E -C options:

    #line 1 "fred.c"
    int a;
    #line 4
    int b;
                   // This is a C++ comment
    int c;
  4. Preprocessor Output Example 3 - Macro Function Argument

    For the following source code fragment:

    #define mm(aa) aa
    int a;
    int b;  mm(// This is a C++ comment
                  int blah);
    int c;
            // This is a C++ comment
    int d;

    The output for the -P option:

    int a;
    int b;  int blah;
    int c;
     
    int d;

    The output for the -P -C options:

    int a;
    int b;  int blah;
    int c;
            // This is a C++ comment
    int d;

    The output for the -E option is:

    #line 1 "fred.c"
    int a;
    int b;
    int blah;
    int c;
     
    int d;

    The output for the -E -C option is:

    #line 1 "fred.c"
    int a;
    int b;
    int blah;
    int c;
            // This is a C++ comment
    int d;
  5. Compile Example

    To compile myprogram.c. so that C++ comments are recognized as comments, enter:

    xlc myprogram.c -qcpluscmt

Related information