cpluscmt

Option Type Default Value #pragma options C C++
-qoption nocpluscmt CPLUSCMT x  

Syntax

    -qcpluscmt | -qnocpluscmt 
    CPLUSCMT | NOCPLUSCMT 

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

Notes
The #pragma options directive must appear before the first statement in the C language source file and applies to the entire file.

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 ANSI C. The result of the following valid ANSI C 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 (??/).

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

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 ANSI 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 ANSI 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;

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;

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;

A comment may contain a sequence of valid multibyte characters.

The character sequence // begins a C++ comment, except within a header name, a character constant, a string literal, or a comment. The character sequence //, or /* and */ are ignored within a C++ comment. Comments do not nest.

Macro replacement is not performed within comments.

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

xlC myprogram.c -qcpluscmt


List of Batch Compiler Options and Their Defaults
Options that Specify Preprocessor Options
Equivalent Batch Compile-Link and Incremental Build Options