comparison gcc/doc/cpp.texi @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
comparison
equal deleted inserted replaced
131:84e7813d76e9 145:1830386684a0
8 8
9 @include gcc-common.texi 9 @include gcc-common.texi
10 10
11 @copying 11 @copying
12 @c man begin COPYRIGHT 12 @c man begin COPYRIGHT
13 Copyright @copyright{} 1987-2018 Free Software Foundation, Inc. 13 Copyright @copyright{} 1987-2020 Free Software Foundation, Inc.
14 14
15 Permission is granted to copy, distribute and/or modify this document 15 Permission is granted to copy, distribute and/or modify this document
16 under the terms of the GNU Free Documentation License, Version 1.3 or 16 under the terms of the GNU Free Documentation License, Version 1.3 or
17 any later version published by the Free Software Foundation. A copy of 17 any later version published by the Free Software Foundation. A copy of
18 the license is included in the 18 the license is included in the
272 selected execution character set. All other escapes are replaced by 272 selected execution character set. All other escapes are replaced by
273 the character in the source character set that they represent, then 273 the character in the source character set that they represent, then
274 converted to the execution character set, just like unescaped 274 converted to the execution character set, just like unescaped
275 characters. 275 characters.
276 276
277 In identifiers, characters outside the ASCII range can only be 277 In identifiers, characters outside the ASCII range can be specified
278 specified with the @samp{\u} and @samp{\U} escapes, not used 278 with the @samp{\u} and @samp{\U} escapes or used directly in the input
279 directly. If strict ISO C90 conformance is specified with an option 279 encoding. If strict ISO C90 conformance is specified with an option
280 such as @option{-std=c90}, or @option{-fno-extended-identifiers} is 280 such as @option{-std=c90}, or @option{-fno-extended-identifiers} is
281 used, then those escapes are not permitted in identifiers. 281 used, then those constructs are not permitted in identifiers.
282 282
283 @node Initial processing 283 @node Initial processing
284 @section Initial processing 284 @section Initial processing
285 285
286 The preprocessor performs a series of textual transformations on its 286 The preprocessor performs a series of textual transformations on its
501 501
502 In the 1999 C standard, identifiers may contain letters which are not 502 In the 1999 C standard, identifiers may contain letters which are not
503 part of the ``basic source character set'', at the implementation's 503 part of the ``basic source character set'', at the implementation's
504 discretion (such as accented Latin letters, Greek letters, or Chinese 504 discretion (such as accented Latin letters, Greek letters, or Chinese
505 ideograms). This may be done with an extended character set, or the 505 ideograms). This may be done with an extended character set, or the
506 @samp{\u} and @samp{\U} escape sequences. GCC only accepts such 506 @samp{\u} and @samp{\U} escape sequences.
507 characters in the @samp{\u} and @samp{\U} forms.
508 507
509 As an extension, GCC treats @samp{$} as a letter. This is for 508 As an extension, GCC treats @samp{$} as a letter. This is for
510 compatibility with some systems, such as VMS, where @samp{$} is commonly 509 compatibility with some systems, such as VMS, where @samp{$} is commonly
511 used in system-defined function and object names. @samp{$} is not a 510 used in system-defined function and object names. @samp{$} is not a
512 letter in strictly conforming mode, or if you specify the @option{-$} 511 letter in strictly conforming mode, or if you specify the @option{-$}
582 Digraph: <% %> <: :> %: %:%: 581 Digraph: <% %> <: :> %: %:%:
583 Punctuator: @{ @} [ ] # ## 582 Punctuator: @{ @} [ ] # ##
584 @end smallexample 583 @end smallexample
585 584
586 @cindex other tokens 585 @cindex other tokens
587 Any other single character is considered ``other''. It is passed on to 586 Any other single byte is considered ``other'' and passed on to the
588 the preprocessor's output unmolested. The C compiler will almost 587 preprocessor's output unchanged. The C compiler will almost certainly
589 certainly reject source code containing ``other'' tokens. In ASCII, the 588 reject source code containing ``other'' tokens. In ASCII, the only
590 only other characters are @samp{@@}, @samp{$}, @samp{`}, and control 589 ``other'' characters are @samp{@@}, @samp{$}, @samp{`}, and control
591 characters other than NUL (all bits zero). (Note that @samp{$} is 590 characters other than NUL (all bits zero). (Note that @samp{$} is
592 normally considered a letter.) All characters with the high bit set 591 normally considered a letter.) All bytes with the high bit set
593 (numeric range 0x7F--0xFF) are also ``other'' in the present 592 (numeric range 0x7F--0xFF) that were not succesfully interpreted as
594 implementation. This will change when proper support for international 593 part of an extended character in the input encoding are also ``other''
595 character sets is added to GCC@. 594 in the present implementation.
596 595
597 NUL is a special case because of the high probability that its 596 NUL is a special case because of the high probability that its
598 appearance is accidental, and because it may be invisible to the user 597 appearance is accidental, and because it may be invisible to the user
599 (many terminals do not display NUL at all). Within comments, NULs are 598 (many terminals do not display NUL at all). Within comments, NULs are
600 silently ignored, just as any other character would be. In running 599 silently ignored, just as any other character would be. In running
956 prevent the file from ever being read again, by either @samp{#import} or 955 prevent the file from ever being read again, by either @samp{#import} or
957 @samp{#include}. You should not rely on this; do not use both 956 @samp{#include}. You should not rely on this; do not use both
958 @samp{#import} and @samp{#include} to refer to the same header file. 957 @samp{#import} and @samp{#include} to refer to the same header file.
959 958
960 Another way to prevent a header file from being included more than once 959 Another way to prevent a header file from being included more than once
961 is with the @samp{#pragma once} directive. If @samp{#pragma once} is 960 is with the @samp{#pragma once} directive (@pxref{Pragmas}).
962 seen when scanning a header file, that file will never be read again, no
963 matter what.
964
965 @samp{#pragma once} does not have the problems that @samp{#import} does, 961 @samp{#pragma once} does not have the problems that @samp{#import} does,
966 but it is not recognized by all preprocessors, so you cannot rely on it 962 but it is not recognized by all preprocessors, so you cannot rely on it
967 in a portable program. 963 in a portable program.
968 964
969 @node Computed Includes 965 @node Computed Includes
1131 tells GCC to consider the rest of the current include file a system 1127 tells GCC to consider the rest of the current include file a system
1132 header, no matter where it was found. Code that comes before the 1128 header, no matter where it was found. Code that comes before the
1133 @samp{#pragma} in the file is not affected. @code{@w{#pragma GCC 1129 @samp{#pragma} in the file is not affected. @code{@w{#pragma GCC
1134 system_header}} has no effect in the primary source file. 1130 system_header}} has no effect in the primary source file.
1135 @end itemize 1131 @end itemize
1132
1133 On some targets, such as RS/6000 AIX, GCC implicitly surrounds all
1134 system headers with an @samp{extern "C"} block when compiling as C++.
1136 1135
1137 @node Macros 1136 @node Macros
1138 @chapter Macros 1137 @chapter Macros
1139 1138
1140 A @dfn{macro} is a fragment of code which has been given a name. 1139 A @dfn{macro} is a fragment of code which has been given a name.
3156 * Ifdef:: 3155 * Ifdef::
3157 * If:: 3156 * If::
3158 * Defined:: 3157 * Defined::
3159 * Else:: 3158 * Else::
3160 * Elif:: 3159 * Elif::
3160 * @code{__has_attribute}::
3161 * @code{__has_cpp_attribute}::
3162 * @code{__has_builtin}::
3163 * @code{__has_include}::
3161 @end menu 3164 @end menu
3162 3165
3163 @node Ifdef 3166 @node Ifdef
3164 @subsection Ifdef 3167 @subsection Ifdef
3165 @findex #ifdef 3168 @findex #ifdef
3420 @samp{#elif} directives within it have failed. 3423 @samp{#elif} directives within it have failed.
3421 3424
3422 @samp{#else} is allowed after any number of @samp{#elif} directives, but 3425 @samp{#else} is allowed after any number of @samp{#elif} directives, but
3423 @samp{#elif} may not follow @samp{#else}. 3426 @samp{#elif} may not follow @samp{#else}.
3424 3427
3428 @node @code{__has_attribute}
3429 @subsection @code{__has_attribute}
3430 @cindex @code{__has_attribute}
3431
3432 The special operator @code{__has_attribute (@var{operand})} may be used
3433 in @samp{#if} and @samp{#elif} expressions to test whether the attribute
3434 referenced by its @var{operand} is recognized by GCC. Using the operator
3435 in other contexts is not valid. In C code, @var{operand} must be
3436 a valid identifier. In C++ code, @var{operand} may be optionally
3437 introduced by the @code{@var{attribute-scope}::} prefix.
3438 The @var{attribute-scope} prefix identifies the ``namespace'' within
3439 which the attribute is recognized. The scope of GCC attributes is
3440 @samp{gnu} or @samp{__gnu__}. The @code{__has_attribute} operator by
3441 itself, without any @var{operand} or parentheses, acts as a predefined
3442 macro so that support for it can be tested in portable code. Thus,
3443 the recommended use of the operator is as follows:
3444
3445 @smallexample
3446 #if defined __has_attribute
3447 # if __has_attribute (nonnull)
3448 # define ATTR_NONNULL __attribute__ ((nonnull))
3449 # endif
3450 #endif
3451 @end smallexample
3452
3453 The first @samp{#if} test succeeds only when the operator is supported
3454 by the version of GCC (or another compiler) being used. Only when that
3455 test succeeds is it valid to use @code{__has_attribute} as a preprocessor
3456 operator. As a result, combining the two tests into a single expression as
3457 shown below would only be valid with a compiler that supports the operator
3458 but not with others that don't.
3459
3460 @smallexample
3461 #if defined __has_attribute && __has_attribute (nonnull) /* not portable */
3462 @dots{}
3463 #endif
3464 @end smallexample
3465
3466 @node @code{__has_cpp_attribute}
3467 @subsection @code{__has_cpp_attribute}
3468 @cindex @code{__has_cpp_attribute}
3469
3470 The special operator @code{__has_cpp_attribute (@var{operand})} may be used
3471 in @samp{#if} and @samp{#elif} expressions in C++ code to test whether
3472 the attribute referenced by its @var{operand} is recognized by GCC.
3473 @code{__has_cpp_attribute (@var{operand})} is equivalent to
3474 @code{__has_attribute (@var{operand})} except that when @var{operand}
3475 designates a supported standard attribute it evaluates to an integer
3476 constant of the form @code{YYYYMM} indicating the year and month when
3477 the attribute was first introduced into the C++ standard. For additional
3478 information including the dates of the introduction of current standard
3479 attributes, see @w{@uref{https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations/,
3480 SD-6: SG10 Feature Test Recommendations}}.
3481
3482 @node @code{__has_builtin}
3483 @subsection @code{__has_builtin}
3484 @cindex @code{__has_builtin}
3485
3486 The special operator @code{__has_builtin (@var{operand})} may be used in
3487 constant integer contexts and in preprocessor @samp{#if} and @samp{#elif}
3488 expressions to test whether the symbol named by its @var{operand} is
3489 recognized as a built-in function by GCC in the current language and
3490 conformance mode. It evaluates to a constant integer with a nonzero
3491 value if the argument refers to such a function, and to zero otherwise.
3492 The operator may also be used in preprocessor @samp{#if} and @samp{#elif}
3493 expressions. The @code{__has_builtin} operator by itself, without any
3494 @var{operand} or parentheses, acts as a predefined macro so that support
3495 for it can be tested in portable code. Thus, the recommended use of
3496 the operator is as follows:
3497
3498 @smallexample
3499 #if defined __has_builtin
3500 # if __has_builtin (__builtin_object_size)
3501 # define builtin_object_size(ptr) __builtin_object_size (ptr, 2)
3502 # endif
3503 #endif
3504 #ifndef builtin_object_size
3505 # define builtin_object_size(ptr) ((size_t)-1)
3506 #endif
3507 @end smallexample
3508
3509 @node @code{__has_include}
3510 @subsection @code{__has_include}
3511 @cindex @code{__has_include}
3512
3513 The special operator @code{__has_include (@var{operand})} may be used in
3514 @samp{#if} and @samp{#elif} expressions to test whether the header referenced
3515 by its @var{operand} can be included using the @samp{#include} directive. Using
3516 the operator in other contexts is not valid. The @var{operand} takes
3517 the same form as the file in the @samp{#include} directive (@pxref{Include
3518 Syntax}) and evaluates to a nonzero value if the header can be included and
3519 to zero otherwise. Note that that the ability to include a header doesn't
3520 imply that the header doesn't contain invalid constructs or @samp{#error}
3521 directives that would cause the preprocessor to fail.
3522
3523 The @code{__has_include} operator by itself, without any @var{operand} or
3524 parentheses, acts as a predefined macro so that support for it can be tested
3525 in portable code. Thus, the recommended use of the operator is as follows:
3526
3527 @smallexample
3528 #if defined __has_include
3529 # if __has_include (<stdatomic.h>)
3530 # include <stdatomic.h>
3531 # endif
3532 #endif
3533 @end smallexample
3534
3535 The first @samp{#if} test succeeds only when the operator is supported
3536 by the version of GCC (or another compiler) being used. Only when that
3537 test succeeds is it valid to use @code{__has_include} as a preprocessor
3538 operator. As a result, combining the two tests into a single expression
3539 as shown below would only be valid with a compiler that supports the operator
3540 but not with others that don't.
3541
3542 @smallexample
3543 #if defined __has_include && __has_include ("header.h") /* not portable */
3544 @dots{}
3545 #endif
3546 @end smallexample
3547
3425 @node Deleted Code 3548 @node Deleted Code
3426 @section Deleted Code 3549 @section Deleted Code
3427 @cindex commenting out code 3550 @cindex commenting out code
3428 3551
3429 If you replace or delete a part of the program but want to keep the old 3552 If you replace or delete a part of the program but want to keep the old
3548 idea of the directory containing the current file. 3671 idea of the directory containing the current file.
3549 3672
3550 @node Pragmas 3673 @node Pragmas
3551 @chapter Pragmas 3674 @chapter Pragmas
3552 3675
3676 @cindex pragma directive
3677
3553 The @samp{#pragma} directive is the method specified by the C standard 3678 The @samp{#pragma} directive is the method specified by the C standard
3554 for providing additional information to the compiler, beyond what is 3679 for providing additional information to the compiler, beyond what is
3555 conveyed in the language itself. The forms of this directive 3680 conveyed in the language itself. The forms of this directive
3556 (commonly known as @dfn{pragmas}) specified by C standard are prefixed with 3681 (commonly known as @dfn{pragmas}) specified by C standard are prefixed with
3557 @code{STDC}. A C compiler is free to attach any meaning it likes to other 3682 @code{STDC}. A C compiler is free to attach any meaning it likes to other
3558 pragmas. All GNU-defined, supported pragmas have been given a 3683 pragmas. Most GNU-defined, supported pragmas have been given a
3559 @code{GCC} prefix. 3684 @code{GCC} prefix.
3560 3685
3561 @cindex @code{_Pragma} 3686 @cindex @code{_Pragma}
3562 C99 introduced the @code{@w{_Pragma}} operator. This feature addresses a 3687 C99 introduced the @code{@w{_Pragma}} operator. This feature addresses a
3563 major problem with @samp{#pragma}: being a directive, it cannot be 3688 major problem with @samp{#pragma}: being a directive, it cannot be
3655 a warning diagnostic with the text @samp{message}. The message 3780 a warning diagnostic with the text @samp{message}. The message
3656 contained in the pragma must be a single string literal. Similarly, 3781 contained in the pragma must be a single string literal. Similarly,
3657 @code{#pragma GCC error "message"} issues an error message. Unlike 3782 @code{#pragma GCC error "message"} issues an error message. Unlike
3658 the @samp{#warning} and @samp{#error} directives, these pragmas can be 3783 the @samp{#warning} and @samp{#error} directives, these pragmas can be
3659 embedded in preprocessor macros using @samp{_Pragma}. 3784 embedded in preprocessor macros using @samp{_Pragma}.
3785
3786 @item #pragma once
3787 If @code{#pragma once} is seen when scanning a header file, that
3788 file will never be read again, no matter what. It is a less-portable
3789 alternative to using @samp{#ifndef} to guard the contents of header files
3790 against multiple inclusions.
3660 3791
3661 @end ftable 3792 @end ftable
3662 3793
3663 @node Other Directives 3794 @node Other Directives
3664 @chapter Other Directives 3795 @chapter Other Directives
4073 @anchor{Identifier characters} 4204 @anchor{Identifier characters}
4074 4205
4075 The C and C++ standards allow identifiers to be composed of @samp{_} 4206 The C and C++ standards allow identifiers to be composed of @samp{_}
4076 and the alphanumeric characters. C++ also allows universal character 4207 and the alphanumeric characters. C++ also allows universal character
4077 names. C99 and later C standards permit both universal character 4208 names. C99 and later C standards permit both universal character
4078 names and implementation-defined characters. 4209 names and implementation-defined characters. In both C and C++ modes,
4210 GCC accepts in identifiers exactly those extended characters that
4211 correspond to universal character names permitted by the chosen
4212 standard.
4079 4213
4080 GCC allows the @samp{$} character in identifiers as an extension for 4214 GCC allows the @samp{$} character in identifiers as an extension for
4081 most targets. This is true regardless of the @option{std=} switch, 4215 most targets. This is true regardless of the @option{std=} switch,
4082 since this extension cannot conflict with standards-conforming 4216 since this extension cannot conflict with standards-conforming
4083 programs. When preprocessing assembler, however, dollars are not 4217 programs. When preprocessing assembler, however, dollars are not