langlvl

Option Type Default Value #pragma options C C++
-qoption langlvl=ansi* LANGlvl=language x x

Syntax

    -qlanglvl=language 
    LANGLVL=language 

Purpose
Selects the C or C++ language level for the compilation.

Default
The default language level is ansi when you invoke the compiler using the xlC, xlc, or c89 command. The default language level is extended when you invoke the compiler using the icc command.

You can use either of the following preprocessor directives to specify the language level in your C or C++ source program:

    #pragma options langlvl=language
    #pragma langlvl(language)

The pragma directive must appear before any noncommentary lines in the source code.

Notes
For C programs, language is one of:

ansi Compilation conforms to the ANSI C standard.
saal2 Compilation conforms to the SAA C Level 2 CPI language definition, with some exceptions.
saa Compilation conforms to the current SAA C CPI language definition. This is currently SAA C Level 2.
EXTended Provides compatibility with the RT compiler and classic.
classic Allows the compilation of non-ANSI programs, and conforms closely to the K&R level preprocessor.

 

For C++ programs, language is one of:

ansi Compilation conforms to the ANSI C standard for C programs, and the proposed ANSI working paper for C++ programs. The macro __ANSI__ is predefined to be 1.
extended Compilation conforms is the same as ansi mode, with some differences. Refer to Conflicts Between extended C and Other Levels for details.
compat Compilation is compatible with older levels of the C++ language. Module initialization occurs in link order. The macro __COMPAT__ is predefinedto be 1.

The effects of using this option on C++ programs are:

  • classes declared or defined within classes or declared within argument lists are given the scope of the closest nonclass.
  • typedefs declared within classes are given the scope of the closest nonclass.
  • The overload statement is recognized and ignored.
  • An expression showing the dimension in a delete expression is parsed and ignored. For example:
    delete [20] p; // 20 is ignored.
  • Where a conversion to a reference type uses a compiler temporary type, the reference need not be to a const type.
  • Initializations can be bypassed as long as they are not constructor initializations.
  • Returning a void expression from a function that returns void is allowed.
  • operator++ and operator-- without the second zero argument are matched with both prefix and postfix ++ and --.
  • $ sign is allowed in identifiers.
  • friend X; is allowed when X has not yet been introduced as a class name. For example:
    friend X; // is equivalanet to : friend class X;
  • Extra tokens following preprocessor directives are allowed. For example:
    #endif Comment
  • A class declaration with no declarator can have the same name as its container. For example:
    class A {
    class A;
    }
  • A trailing comma is allowed in an enumeration constant list. For example:
    enum E { e, }; // allowed
  • A cast expression can contain a storage class specifier. For example:
    (static int *) pi; //allowed
  • Overloaded operators
    class B {
    int operator==(unsigned int);
    operator int();
       };
       B bobj;
        int i;
        ... bobj == i // exact match
  • Not returning avalue from a function that has a return value generates a warning instead of an error.

 

Exceptions to the ansi mode addressed by classic are as follows:

Tokenization Tokens introduced by macro expansion may be combined with adjacent tokens in some cases. Historically, this was an artifact of the text-based implementations of older preprocessors, and because, in older implementations, the preprocessor was a separate program whose output was passed on to the compiler.

For similar reasons, tokens separated only by a comment may also be combined to form a single token. Here is a summary of how tokenization of a program compiled in classic mode is performed:

  1. At a given point in the source file, the next token is the longest sequence of characters that can possibly form a token. For example, i+++++j is tokenized as i ++ ++ + j even though i ++ + ++ j may have resulted in a correct program.
  2. If the token formed is an identifier and a macro name, the macro is replaced by the text of the tokens specified on its #define directive. Each parameter is replaced by the text of the corresponding argument. Comments are removed from both the arguments and the macro text.
  3. Scanning is resumed at the first step from the point at which the macro was replaced, as if it were part of the original program.
  4. When the entire program has been preprocessed, the result is scanned again by the compiler as in the first step. The second and third steps do not apply here since there will be no macros to replace. Constructs generated by the first three steps that resemble preprocessing directives are not processed as such.

It is in the third and fourth steps that the text of adjacent but previously separate tokens may be combined to form new tokens.

The \ character for line continuation is accepted only in string and character literals and on preprocessing directives.

Constructs such as:

   #if 0
      "unterminated
   #endif
   #define US "Unterminating string
   char *s = US terminated now"

will not generate diagnostic messages, since the first is an unterminated literal in a FALSE block, and the second is completed after macro expansion. However:

   char *s = US;

will generate a diagnostic message since the string literal in US is not completed before the end of the line.

Empty character literals are allowed. The value of the literal is sero.

Preprocessing directives The # token must appear in the first column of the line. The token immediately following # is available for macro expansion. The line can be continued with \ only if the name of the directive and, in the following example, the ( has been seen:
   #define f(a,b) a+b
   f\
   (1,2)      /* accepted */
   #define f(a,b) a+b
   f(\
   1,2)       /* not accepted */

The rules concerning \ apply whether or not the directive is valid. For example,

   #\
   define M 1   /* not allowed */
   #def\
   ine M 1      /* not allowed */
   #define\
   M 1          /* allowed */
   #dfine\
   M 1          /* equivalent to #dfine M 1, even
                   though #dfine is not valid  */

Following are the preprocessor directive differences between classic mode and ansi mode. Directives not listed here behave similarly in both modes.

#ifdef/
#ifndef
When the first token is not an identifier, no diagnostic message is generated, and the condition is FALSE.
#else When there are extra tokens, no diagnostic message is generated.
#endif When there are extra tokens, no diagnostic message is generated.
#include The < and > are separate tokens. The header is formed by combining the spelling of the < and > with the tokens between them. Therefore /* and // are recognized as comments (and are always stripped), and the " and ' do begin literals within the < and >. (Remember that in C programs, C++-style comments // are recognized when -qcpluscmt is specified.)
#line The spelling of all tokens which are not part of the line number form the new file name. These tokens need not be string literals.
#error Not recognized in classic mode.
#define A valid macro parameter list consists of zero or more identifiers each separated by commas. The commas are ignored and the parameter list is constructed as if they were not specified. The parameter names need not be unique. If there is a conflict, the last name specified is recognized.

For an invalid parameter list, a warning is issued. If a macro name is redefined with a new definition, a warning will be issued and the new definition used.

#undef When there are extra tokens, no diagnostic message is generated.
Macro expansion
  • When the number of arguments on a macro invocation does not match the number of parameters, a warning is issued.
  • If the ( token is present after the macro name of a function-like macro, it is treated as too few arguments (as above) and a warning is issued.
  • Parameters are replaced in string literals and character literals.
  • Examples:
       #define M()    1
       #define N(a)   (a)
       #define O(a,b) ((a) + (b))
       M();  /* no error */
       N();  /* empty argument */
       O();  /* empty first argument 
                and too few arguments */
Text Output No text is generated to replace comments.


List of Compiler Options and Their Defaults
Options that Specify Compiler Characteristics