Index: stable/10/contrib/gcc/c-cppbuiltin.c =================================================================== --- stable/10/contrib/gcc/c-cppbuiltin.c (revision 286712) +++ stable/10/contrib/gcc/c-cppbuiltin.c (revision 286713) @@ -1,761 +1,763 @@ /* Define builtin-in macros for the C family front ends. Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc. This file is part of GCC. GCC is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GCC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GCC; see the file COPYING. If not, write to the Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "config.h" #include "system.h" #include "coretypes.h" #include "tm.h" #include "tree.h" #include "version.h" #include "flags.h" #include "real.h" #include "c-common.h" #include "c-pragma.h" #include "output.h" #include "except.h" /* For USING_SJLJ_EXCEPTIONS. */ #include "toplev.h" #include "tm_p.h" /* Target prototypes. */ #include "target.h" #ifndef TARGET_OS_CPP_BUILTINS # define TARGET_OS_CPP_BUILTINS() #endif #ifndef TARGET_OBJFMT_CPP_BUILTINS # define TARGET_OBJFMT_CPP_BUILTINS() #endif #ifndef REGISTER_PREFIX #define REGISTER_PREFIX "" #endif /* Non-static as some targets don't use it. */ void builtin_define_std (const char *) ATTRIBUTE_UNUSED; static void builtin_define_with_value_n (const char *, const char *, size_t); static void builtin_define_with_int_value (const char *, HOST_WIDE_INT); static void builtin_define_with_hex_fp_value (const char *, tree, int, const char *, const char *, const char *); static void builtin_define_stdint_macros (void); static void builtin_define_type_max (const char *, tree, int); static void builtin_define_type_precision (const char *, tree); static void builtin_define_float_constants (const char *, const char *, const char *, tree); static void define__GNUC__ (void); /* Define NAME with value TYPE precision. */ static void builtin_define_type_precision (const char *name, tree type) { builtin_define_with_int_value (name, TYPE_PRECISION (type)); } /* Define the float.h constants for TYPE using NAME_PREFIX, FP_SUFFIX, and FP_CAST. */ static void builtin_define_float_constants (const char *name_prefix, const char *fp_suffix, const char *fp_cast, tree type) { /* Used to convert radix-based values to base 10 values in several cases. In the max_exp -> max_10_exp conversion for 128-bit IEEE, we need at least 6 significant digits for correct results. Using the fraction formed by (log(2)*1e6)/(log(10)*1e6) overflows a 32-bit integer as an intermediate; perhaps someone can find a better approximation, in the mean time, I suspect using doubles won't harm the bootstrap here. */ const double log10_2 = .30102999566398119521; double log10_b; const struct real_format *fmt; char name[64], buf[128]; int dig, min_10_exp, max_10_exp; int decimal_dig; fmt = REAL_MODE_FORMAT (TYPE_MODE (type)); gcc_assert (fmt->b != 10); /* The radix of the exponent representation. */ if (type == float_type_node) builtin_define_with_int_value ("__FLT_RADIX__", fmt->b); log10_b = log10_2 * fmt->log2_b; /* The number of radix digits, p, in the floating-point significand. */ sprintf (name, "__%s_MANT_DIG__", name_prefix); builtin_define_with_int_value (name, fmt->p); /* The number of decimal digits, q, such that any floating-point number with q decimal digits can be rounded into a floating-point number with p radix b digits and back again without change to the q decimal digits, p log10 b if b is a power of 10 floor((p - 1) log10 b) otherwise */ dig = (fmt->p - 1) * log10_b; sprintf (name, "__%s_DIG__", name_prefix); builtin_define_with_int_value (name, dig); /* The minimum negative int x such that b**(x-1) is a normalized float. */ sprintf (name, "__%s_MIN_EXP__", name_prefix); sprintf (buf, "(%d)", fmt->emin); builtin_define_with_value (name, buf, 0); /* The minimum negative int x such that 10**x is a normalized float, ceil (log10 (b ** (emin - 1))) = ceil (log10 (b) * (emin - 1)) Recall that emin is negative, so the integer truncation calculates the ceiling, not the floor, in this case. */ min_10_exp = (fmt->emin - 1) * log10_b; sprintf (name, "__%s_MIN_10_EXP__", name_prefix); sprintf (buf, "(%d)", min_10_exp); builtin_define_with_value (name, buf, 0); /* The maximum int x such that b**(x-1) is a representable float. */ sprintf (name, "__%s_MAX_EXP__", name_prefix); builtin_define_with_int_value (name, fmt->emax); /* The maximum int x such that 10**x is in the range of representable finite floating-point numbers, floor (log10((1 - b**-p) * b**emax)) = floor (log10(1 - b**-p) + log10(b**emax)) = floor (log10(1 - b**-p) + log10(b)*emax) The safest thing to do here is to just compute this number. But since we don't link cc1 with libm, we cannot. We could implement log10 here a series expansion, but that seems too much effort because: Note that the first term, for all extant p, is a number exceedingly close to zero, but slightly negative. Note that the second term is an integer scaling an irrational number, and that because of the floor we are only interested in its integral portion. In order for the first term to have any effect on the integral portion of the second term, the second term has to be exceedingly close to an integer itself (e.g. 123.000000000001 or something). Getting a result that close to an integer requires that the irrational multiplicand have a long series of zeros in its expansion, which doesn't occur in the first 20 digits or so of log10(b). Hand-waving aside, crunching all of the sets of constants above by hand does not yield a case for which the first term is significant, which in the end is all that matters. */ max_10_exp = fmt->emax * log10_b; sprintf (name, "__%s_MAX_10_EXP__", name_prefix); builtin_define_with_int_value (name, max_10_exp); /* The number of decimal digits, n, such that any floating-point number can be rounded to n decimal digits and back again without change to the value. p * log10(b) if b is a power of 10 ceil(1 + p * log10(b)) otherwise The only macro we care about is this number for the widest supported floating type, but we want this value for rendering constants below. */ { double d_decimal_dig = 1 + fmt->p * log10_b; decimal_dig = d_decimal_dig; if (decimal_dig < d_decimal_dig) decimal_dig++; } if (type == long_double_type_node) builtin_define_with_int_value ("__DECIMAL_DIG__", decimal_dig); /* Since, for the supported formats, B is always a power of 2, we construct the following numbers directly as a hexadecimal constants. */ /* The maximum representable finite floating-point number, (1 - b**-p) * b**emax */ { int i, n; char *p; strcpy (buf, "0x0."); n = fmt->p * fmt->log2_b; for (i = 0, p = buf + 4; i + 3 < n; i += 4) *p++ = 'f'; if (i < n) *p++ = "08ce"[n - i]; sprintf (p, "p%d", fmt->emax * fmt->log2_b); if (fmt->pnan < fmt->p) { /* This is an IBM extended double format made up of two IEEE doubles. The value of the long double is the sum of the values of the two parts. The most significant part is required to be the value of the long double rounded to the nearest double. Rounding means we need a slightly smaller value for LDBL_MAX. */ buf[4 + fmt->pnan / 4] = "7bde"[fmt->pnan % 4]; } } sprintf (name, "__%s_MAX__", name_prefix); builtin_define_with_hex_fp_value (name, type, decimal_dig, buf, fp_suffix, fp_cast); /* The minimum normalized positive floating-point number, b**(emin-1). */ sprintf (name, "__%s_MIN__", name_prefix); sprintf (buf, "0x1p%d", (fmt->emin - 1) * fmt->log2_b); builtin_define_with_hex_fp_value (name, type, decimal_dig, buf, fp_suffix, fp_cast); /* The difference between 1 and the least value greater than 1 that is representable in the given floating point type, b**(1-p). */ sprintf (name, "__%s_EPSILON__", name_prefix); if (fmt->pnan < fmt->p) /* This is an IBM extended double format, so 1.0 + any double is representable precisely. */ sprintf (buf, "0x1p%d", (fmt->emin - fmt->p) * fmt->log2_b); else sprintf (buf, "0x1p%d", (1 - fmt->p) * fmt->log2_b); builtin_define_with_hex_fp_value (name, type, decimal_dig, buf, fp_suffix, fp_cast); /* For C++ std::numeric_limits::denorm_min. The minimum denormalized positive floating-point number, b**(emin-p). Zero for formats that don't support denormals. */ sprintf (name, "__%s_DENORM_MIN__", name_prefix); if (fmt->has_denorm) { sprintf (buf, "0x1p%d", (fmt->emin - fmt->p) * fmt->log2_b); builtin_define_with_hex_fp_value (name, type, decimal_dig, buf, fp_suffix, fp_cast); } else { sprintf (buf, "0.0%s", fp_suffix); builtin_define_with_value (name, buf, 0); } sprintf (name, "__%s_HAS_DENORM__", name_prefix); builtin_define_with_value (name, fmt->has_denorm ? "1" : "0", 0); /* For C++ std::numeric_limits::has_infinity. */ sprintf (name, "__%s_HAS_INFINITY__", name_prefix); builtin_define_with_int_value (name, MODE_HAS_INFINITIES (TYPE_MODE (type))); /* For C++ std::numeric_limits::has_quiet_NaN. We do not have a predicate to distinguish a target that has both quiet and signalling NaNs from a target that has only quiet NaNs or only signalling NaNs, so we assume that a target that has any kind of NaN has quiet NaNs. */ sprintf (name, "__%s_HAS_QUIET_NAN__", name_prefix); builtin_define_with_int_value (name, MODE_HAS_NANS (TYPE_MODE (type))); } /* Define __DECx__ constants for TYPE using NAME_PREFIX and SUFFIX. */ static void builtin_define_decimal_float_constants (const char *name_prefix, const char *suffix, tree type) { const struct real_format *fmt; char name[64], buf[128], *p; int digits; fmt = REAL_MODE_FORMAT (TYPE_MODE (type)); /* The number of radix digits, p, in the significand. */ sprintf (name, "__%s_MANT_DIG__", name_prefix); builtin_define_with_int_value (name, fmt->p); /* The minimum negative int x such that b**(x-1) is a normalized float. */ sprintf (name, "__%s_MIN_EXP__", name_prefix); sprintf (buf, "(%d)", fmt->emin); builtin_define_with_value (name, buf, 0); /* The maximum int x such that b**(x-1) is a representable float. */ sprintf (name, "__%s_MAX_EXP__", name_prefix); builtin_define_with_int_value (name, fmt->emax); /* Compute the minimum representable value. */ sprintf (name, "__%s_MIN__", name_prefix); sprintf (buf, "1E%d%s", fmt->emin, suffix); builtin_define_with_value (name, buf, 0); /* Compute the maximum representable value. */ sprintf (name, "__%s_MAX__", name_prefix); p = buf; for (digits = fmt->p; digits; digits--) { *p++ = '9'; if (digits == fmt->p) *p++ = '.'; } *p = 0; /* fmt->p plus 1, to account for the decimal point. */ sprintf (&buf[fmt->p + 1], "E%d%s", fmt->emax, suffix); builtin_define_with_value (name, buf, 0); /* Compute epsilon (the difference between 1 and least value greater than 1 representable). */ sprintf (name, "__%s_EPSILON__", name_prefix); sprintf (buf, "1E-%d%s", fmt->p - 1, suffix); builtin_define_with_value (name, buf, 0); /* Minimum denormalized postive decimal value. */ sprintf (name, "__%s_DEN__", name_prefix); p = buf; for (digits = fmt->p; digits > 1; digits--) { *p++ = '0'; if (digits == fmt->p) *p++ = '.'; } *p = 0; sprintf (&buf[fmt->p], "1E%d%s", fmt->emin, suffix); builtin_define_with_value (name, buf, 0); } /* Define __GNUC__, __GNUC_MINOR__ and __GNUC_PATCHLEVEL__. */ static void define__GNUC__ (void) { /* The format of the version string, enforced below, is ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)? */ const char *q, *v = version_string; while (*v && !ISDIGIT (*v)) v++; gcc_assert (*v && (v <= version_string || v[-1] == '-')); q = v; while (ISDIGIT (*v)) v++; builtin_define_with_value_n ("__GNUC__", q, v - q); if (c_dialect_cxx ()) builtin_define_with_value_n ("__GNUG__", q, v - q); gcc_assert (*v == '.' && ISDIGIT (v[1])); q = ++v; while (ISDIGIT (*v)) v++; builtin_define_with_value_n ("__GNUC_MINOR__", q, v - q); if (*v == '.') { gcc_assert (ISDIGIT (v[1])); q = ++v; while (ISDIGIT (*v)) v++; builtin_define_with_value_n ("__GNUC_PATCHLEVEL__", q, v - q); } else builtin_define_with_value_n ("__GNUC_PATCHLEVEL__", "0", 1); gcc_assert (!*v || *v == ' ' || *v == '-'); } /* Define macros used by . Currently only defines limits for intmax_t, used by the testsuite. */ static void builtin_define_stdint_macros (void) { int intmax_long; if (intmax_type_node == long_long_integer_type_node) intmax_long = 2; else if (intmax_type_node == long_integer_type_node) intmax_long = 1; else if (intmax_type_node == integer_type_node) intmax_long = 0; else gcc_unreachable (); builtin_define_type_max ("__INTMAX_MAX__", intmax_type_node, intmax_long); } /* Hook that registers front end and target-specific built-ins. */ void c_cpp_builtins (cpp_reader *pfile) { /* -undef turns off target-specific built-ins. */ if (flag_undef) return; define__GNUC__ (); /* For stddef.h. They require macros defined in c-common.c. */ c_stddef_cpp_builtins (); if (c_dialect_cxx ()) { if (flag_weak && SUPPORTS_ONE_ONLY) cpp_define (pfile, "__GXX_WEAK__=1"); else cpp_define (pfile, "__GXX_WEAK__=0"); if (warn_deprecated) cpp_define (pfile, "__DEPRECATED"); } /* Note that we define this for C as well, so that we know if __attribute__((cleanup)) will interface with EH. */ if (flag_exceptions) cpp_define (pfile, "__EXCEPTIONS"); /* Represents the C++ ABI version, always defined so it can be used while preprocessing C and assembler. */ if (flag_abi_version == 0) /* Use a very large value so that: #if __GXX_ABI_VERSION >= will work whether the user explicitly says "-fabi-version=x" or "-fabi-version=0". Do not use INT_MAX because that will be different from system to system. */ builtin_define_with_int_value ("__GXX_ABI_VERSION", 999999); else if (flag_abi_version == 1) /* Due to a historical accident, this version had the value "102". */ builtin_define_with_int_value ("__GXX_ABI_VERSION", 102); else /* Newer versions have values 1002, 1003, .... */ builtin_define_with_int_value ("__GXX_ABI_VERSION", 1000 + flag_abi_version); /* libgcc needs to know this. */ if (USING_SJLJ_EXCEPTIONS) cpp_define (pfile, "__USING_SJLJ_EXCEPTIONS__"); /* limits.h needs to know these. */ builtin_define_type_max ("__SCHAR_MAX__", signed_char_type_node, 0); builtin_define_type_max ("__SHRT_MAX__", short_integer_type_node, 0); builtin_define_type_max ("__INT_MAX__", integer_type_node, 0); builtin_define_type_max ("__LONG_MAX__", long_integer_type_node, 1); builtin_define_type_max ("__LONG_LONG_MAX__", long_long_integer_type_node, 2); builtin_define_type_max ("__WCHAR_MAX__", wchar_type_node, 0); builtin_define_type_precision ("__CHAR_BIT__", char_type_node); /* stdint.h (eventually) and the testsuite need to know these. */ builtin_define_stdint_macros (); /* float.h needs to know these. */ builtin_define_with_int_value ("__FLT_EVAL_METHOD__", TARGET_FLT_EVAL_METHOD); /* And decfloat.h needs this. */ builtin_define_with_int_value ("__DEC_EVAL_METHOD__", TARGET_DEC_EVAL_METHOD); builtin_define_float_constants ("FLT", "F", "%s", float_type_node); /* Cast the double precision constants when single precision constants are specified. The correct result is computed by the compiler when using macros that include a cast. This has the side-effect of making the value unusable in const expressions. */ if (flag_single_precision_constant) builtin_define_float_constants ("DBL", "L", "((double)%s)", double_type_node); else builtin_define_float_constants ("DBL", "", "%s", double_type_node); builtin_define_float_constants ("LDBL", "L", "%s", long_double_type_node); /* For decfloat.h. */ builtin_define_decimal_float_constants ("DEC32", "DF", dfloat32_type_node); builtin_define_decimal_float_constants ("DEC64", "DD", dfloat64_type_node); builtin_define_decimal_float_constants ("DEC128", "DL", dfloat128_type_node); /* For use in assembly language. */ builtin_define_with_value ("__REGISTER_PREFIX__", REGISTER_PREFIX, 0); builtin_define_with_value ("__USER_LABEL_PREFIX__", user_label_prefix, 0); /* Misc. */ builtin_define_with_value ("__VERSION__", version_string, 1); if (flag_gnu89_inline) cpp_define (pfile, "__GNUC_GNU_INLINE__"); else cpp_define (pfile, "__GNUC_STDC_INLINE__"); /* Definitions for LP64 model. */ if (TYPE_PRECISION (long_integer_type_node) == 64 && POINTER_SIZE == 64 && TYPE_PRECISION (integer_type_node) == 32) { cpp_define (pfile, "_LP64"); cpp_define (pfile, "__LP64__"); } /* Other target-independent built-ins determined by command-line options. */ /* APPLE LOCAL begin blocks */ /* APPLE LOCAL radar 5868913 */ if (flag_blocks) { cpp_define (pfile, "__block=__attribute__((__blocks__(byref)))"); cpp_define (pfile, "__BLOCKS__=1"); } /* APPLE LOCAL end blocks */ if (optimize_size) cpp_define (pfile, "__OPTIMIZE_SIZE__"); if (optimize) cpp_define (pfile, "__OPTIMIZE__"); if (fast_math_flags_set_p ()) cpp_define (pfile, "__FAST_MATH__"); if (flag_really_no_inline) cpp_define (pfile, "__NO_INLINE__"); if (flag_signaling_nans) cpp_define (pfile, "__SUPPORT_SNAN__"); if (flag_finite_math_only) cpp_define (pfile, "__FINITE_MATH_ONLY__=1"); else cpp_define (pfile, "__FINITE_MATH_ONLY__=0"); if (flag_pic) { builtin_define_with_int_value ("__pic__", flag_pic); builtin_define_with_int_value ("__PIC__", flag_pic); } if (flag_iso) cpp_define (pfile, "__STRICT_ANSI__"); if (!flag_signed_char) cpp_define (pfile, "__CHAR_UNSIGNED__"); if (c_dialect_cxx () && TYPE_UNSIGNED (wchar_type_node)) cpp_define (pfile, "__WCHAR_UNSIGNED__"); /* Make the choice of ObjC runtime visible to source code. */ if (c_dialect_objc () && flag_next_runtime) cpp_define (pfile, "__NEXT_RUNTIME__"); /* Show the availability of some target pragmas. */ if (flag_mudflap || targetm.handle_pragma_redefine_extname) cpp_define (pfile, "__PRAGMA_REDEFINE_EXTNAME"); if (targetm.handle_pragma_extern_prefix) cpp_define (pfile, "__PRAGMA_EXTERN_PREFIX"); /* Make the choice of the stack protector runtime visible to source code. The macro names and values here were chosen for compatibility with an earlier implementation, i.e. ProPolice. */ - if (flag_stack_protect == 2) + if (flag_stack_protect == 3) + cpp_define (pfile, "__SSP_STRONG__=3"); + else if (flag_stack_protect == 2) cpp_define (pfile, "__SSP_ALL__=2"); else if (flag_stack_protect == 1) cpp_define (pfile, "__SSP__=1"); if (flag_openmp) cpp_define (pfile, "_OPENMP=200505"); /* A straightforward target hook doesn't work, because of problems linking that hook's body when part of non-C front ends. */ # define preprocessing_asm_p() (cpp_get_options (pfile)->lang == CLK_ASM) # define preprocessing_trad_p() (cpp_get_options (pfile)->traditional) # define builtin_define(TXT) cpp_define (pfile, TXT) # define builtin_assert(TXT) cpp_assert (pfile, TXT) TARGET_CPU_CPP_BUILTINS (); TARGET_OS_CPP_BUILTINS (); TARGET_OBJFMT_CPP_BUILTINS (); /* Support the __declspec keyword by turning them into attributes. Note that the current way we do this may result in a collision with predefined attributes later on. This can be solved by using one attribute, say __declspec__, and passing args to it. The problem with that approach is that args are not accumulated: each new appearance would clobber any existing args. */ if (TARGET_DECLSPEC) builtin_define ("__declspec(x)=__attribute__((x))"); } /* Pass an object-like macro. If it doesn't lie in the user's namespace, defines it unconditionally. Otherwise define a version with two leading underscores, and another version with two leading and trailing underscores, and define the original only if an ISO standard was not nominated. e.g. passing "unix" defines "__unix", "__unix__" and possibly "unix". Passing "_mips" defines "__mips", "__mips__" and possibly "_mips". */ void builtin_define_std (const char *macro) { size_t len = strlen (macro); char *buff = (char *) alloca (len + 5); char *p = buff + 2; char *q = p + len; /* prepend __ (or maybe just _) if in user's namespace. */ memcpy (p, macro, len + 1); if (!( *p == '_' && (p[1] == '_' || ISUPPER (p[1])))) { if (*p != '_') *--p = '_'; if (p[1] != '_') *--p = '_'; } cpp_define (parse_in, p); /* If it was in user's namespace... */ if (p != buff + 2) { /* Define the macro with leading and following __. */ if (q[-1] != '_') *q++ = '_'; if (q[-2] != '_') *q++ = '_'; *q = '\0'; cpp_define (parse_in, p); /* Finally, define the original macro if permitted. */ if (!flag_iso) cpp_define (parse_in, macro); } } /* Pass an object-like macro and a value to define it to. The third parameter says whether or not to turn the value into a string constant. */ void builtin_define_with_value (const char *macro, const char *expansion, int is_str) { char *buf; size_t mlen = strlen (macro); size_t elen = strlen (expansion); size_t extra = 2; /* space for an = and a NUL */ if (is_str) extra += 2; /* space for two quote marks */ buf = (char *) alloca (mlen + elen + extra); if (is_str) sprintf (buf, "%s=\"%s\"", macro, expansion); else sprintf (buf, "%s=%s", macro, expansion); cpp_define (parse_in, buf); } /* Pass an object-like macro and a value to define it to. The third parameter is the length of the expansion. */ static void builtin_define_with_value_n (const char *macro, const char *expansion, size_t elen) { char *buf; size_t mlen = strlen (macro); /* Space for an = and a NUL. */ buf = (char *) alloca (mlen + elen + 2); memcpy (buf, macro, mlen); buf[mlen] = '='; memcpy (buf + mlen + 1, expansion, elen); buf[mlen + elen + 1] = '\0'; cpp_define (parse_in, buf); } /* Pass an object-like macro and an integer value to define it to. */ static void builtin_define_with_int_value (const char *macro, HOST_WIDE_INT value) { char *buf; size_t mlen = strlen (macro); size_t vlen = 18; size_t extra = 2; /* space for = and NUL. */ buf = (char *) alloca (mlen + vlen + extra); memcpy (buf, macro, mlen); buf[mlen] = '='; sprintf (buf + mlen + 1, HOST_WIDE_INT_PRINT_DEC, value); cpp_define (parse_in, buf); } /* Pass an object-like macro a hexadecimal floating-point value. */ static void builtin_define_with_hex_fp_value (const char *macro, tree type ATTRIBUTE_UNUSED, int digits, const char *hex_str, const char *fp_suffix, const char *fp_cast) { REAL_VALUE_TYPE real; char dec_str[64], buf1[256], buf2[256]; /* Hex values are really cool and convenient, except that they're not supported in strict ISO C90 mode. First, the "p-" sequence is not valid as part of a preprocessor number. Second, we get a pedwarn from the preprocessor, which has no context, so we can't suppress the warning with __extension__. So instead what we do is construct the number in hex (because it's easy to get the exact correct value), parse it as a real, then print it back out as decimal. */ real_from_string (&real, hex_str); real_to_decimal (dec_str, &real, sizeof (dec_str), digits, 0); /* Assemble the macro in the following fashion macro = fp_cast [dec_str fp_suffix] */ sprintf (buf1, "%s%s", dec_str, fp_suffix); sprintf (buf2, fp_cast, buf1); sprintf (buf1, "%s=%s", macro, buf2); cpp_define (parse_in, buf1); } /* Define MAX for TYPE based on the precision of the type. IS_LONG is 1 for type "long" and 2 for "long long". We have to handle unsigned types, since wchar_t might be unsigned. */ static void builtin_define_type_max (const char *macro, tree type, int is_long) { static const char *const values[] = { "127", "255", "32767", "65535", "2147483647", "4294967295", "9223372036854775807", "18446744073709551615", "170141183460469231731687303715884105727", "340282366920938463463374607431768211455" }; static const char *const suffixes[] = { "", "U", "L", "UL", "LL", "ULL" }; const char *value, *suffix; char *buf; size_t idx; /* Pre-rendering the values mean we don't have to futz with printing a multi-word decimal value. There are also a very limited number of precisions that we support, so it's really a waste of time. */ switch (TYPE_PRECISION (type)) { case 8: idx = 0; break; case 16: idx = 2; break; case 32: idx = 4; break; case 64: idx = 6; break; case 128: idx = 8; break; default: gcc_unreachable (); } value = values[idx + TYPE_UNSIGNED (type)]; suffix = suffixes[is_long * 2 + TYPE_UNSIGNED (type)]; buf = (char *) alloca (strlen (macro) + 1 + strlen (value) + strlen (suffix) + 1); sprintf (buf, "%s=%s%s", macro, value, suffix); cpp_define (parse_in, buf); } Index: stable/10/contrib/gcc/cfgexpand.c =================================================================== --- stable/10/contrib/gcc/cfgexpand.c (revision 286712) +++ stable/10/contrib/gcc/cfgexpand.c (revision 286713) @@ -1,1732 +1,1800 @@ /* A pass for lowering trees to RTL. Copyright (C) 2004, 2005 Free Software Foundation, Inc. This file is part of GCC. GCC is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GCC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GCC; see the file COPYING. If not, write to the Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "config.h" #include "system.h" #include "coretypes.h" #include "tm.h" #include "tree.h" #include "rtl.h" #include "tm_p.h" #include "basic-block.h" #include "function.h" #include "expr.h" #include "langhooks.h" #include "tree-flow.h" #include "timevar.h" #include "tree-dump.h" #include "tree-pass.h" #include "except.h" #include "flags.h" #include "diagnostic.h" #include "toplev.h" #include "debug.h" #include "params.h" /* Verify that there is exactly single jump instruction since last and attach REG_BR_PROB note specifying probability. ??? We really ought to pass the probability down to RTL expanders and let it re-distribute it when the conditional expands into multiple conditionals. This is however difficult to do. */ static void add_reg_br_prob_note (rtx last, int probability) { if (profile_status == PROFILE_ABSENT) return; for (last = NEXT_INSN (last); last && NEXT_INSN (last); last = NEXT_INSN (last)) if (JUMP_P (last)) { /* It is common to emit condjump-around-jump sequence when we don't know how to reverse the conditional. Special case this. */ if (!any_condjump_p (last) || !JUMP_P (NEXT_INSN (last)) || !simplejump_p (NEXT_INSN (last)) || !NEXT_INSN (NEXT_INSN (last)) || !BARRIER_P (NEXT_INSN (NEXT_INSN (last))) || !NEXT_INSN (NEXT_INSN (NEXT_INSN (last))) || !LABEL_P (NEXT_INSN (NEXT_INSN (NEXT_INSN (last)))) || NEXT_INSN (NEXT_INSN (NEXT_INSN (NEXT_INSN (last))))) goto failed; gcc_assert (!find_reg_note (last, REG_BR_PROB, 0)); REG_NOTES (last) = gen_rtx_EXPR_LIST (REG_BR_PROB, GEN_INT (REG_BR_PROB_BASE - probability), REG_NOTES (last)); return; } if (!last || !JUMP_P (last) || !any_condjump_p (last)) goto failed; gcc_assert (!find_reg_note (last, REG_BR_PROB, 0)); REG_NOTES (last) = gen_rtx_EXPR_LIST (REG_BR_PROB, GEN_INT (probability), REG_NOTES (last)); return; failed: if (dump_file) fprintf (dump_file, "Failed to add probability note\n"); } #ifndef LOCAL_ALIGNMENT #define LOCAL_ALIGNMENT(TYPE, ALIGNMENT) ALIGNMENT #endif #ifndef STACK_ALIGNMENT_NEEDED #define STACK_ALIGNMENT_NEEDED 1 #endif /* This structure holds data relevant to one variable that will be placed in a stack slot. */ struct stack_var { /* The Variable. */ tree decl; /* The offset of the variable. During partitioning, this is the offset relative to the partition. After partitioning, this is relative to the stack frame. */ HOST_WIDE_INT offset; /* Initially, the size of the variable. Later, the size of the partition, if this variable becomes it's partition's representative. */ HOST_WIDE_INT size; /* The *byte* alignment required for this variable. Or as, with the size, the alignment for this partition. */ unsigned int alignb; /* The partition representative. */ size_t representative; /* The next stack variable in the partition, or EOC. */ size_t next; }; #define EOC ((size_t)-1) /* We have an array of such objects while deciding allocation. */ static struct stack_var *stack_vars; static size_t stack_vars_alloc; static size_t stack_vars_num; /* An array of indicies such that stack_vars[stack_vars_sorted[i]].size is non-decreasing. */ static size_t *stack_vars_sorted; /* We have an interference graph between such objects. This graph is lower triangular. */ static bool *stack_vars_conflict; static size_t stack_vars_conflict_alloc; /* The phase of the stack frame. This is the known misalignment of virtual_stack_vars_rtx from PREFERRED_STACK_BOUNDARY. That is, (frame_offset+frame_phase) % PREFERRED_STACK_BOUNDARY == 0. */ static int frame_phase; /* Used during expand_used_vars to remember if we saw any decls for which we'd like to enable stack smashing protection. */ static bool has_protected_decls; /* Used during expand_used_vars. Remember if we say a character buffer smaller than our cutoff threshold. Used for -Wstack-protector. */ static bool has_short_buffer; /* Discover the byte alignment to use for DECL. Ignore alignment we can't do with expected alignment of the stack boundary. */ static unsigned int get_decl_align_unit (tree decl) { unsigned int align; align = DECL_ALIGN (decl); align = LOCAL_ALIGNMENT (TREE_TYPE (decl), align); if (align > PREFERRED_STACK_BOUNDARY) align = PREFERRED_STACK_BOUNDARY; if (cfun->stack_alignment_needed < align) cfun->stack_alignment_needed = align; return align / BITS_PER_UNIT; } /* Allocate SIZE bytes at byte alignment ALIGN from the stack frame. Return the frame offset. */ static HOST_WIDE_INT alloc_stack_frame_space (HOST_WIDE_INT size, HOST_WIDE_INT align) { HOST_WIDE_INT offset, new_frame_offset; new_frame_offset = frame_offset; if (FRAME_GROWS_DOWNWARD) { new_frame_offset -= size + frame_phase; new_frame_offset &= -align; new_frame_offset += frame_phase; offset = new_frame_offset; } else { new_frame_offset -= frame_phase; new_frame_offset += align - 1; new_frame_offset &= -align; new_frame_offset += frame_phase; offset = new_frame_offset; new_frame_offset += size; } frame_offset = new_frame_offset; if (frame_offset_overflow (frame_offset, cfun->decl)) frame_offset = offset = 0; return offset; } /* Accumulate DECL into STACK_VARS. */ static void add_stack_var (tree decl) { if (stack_vars_num >= stack_vars_alloc) { if (stack_vars_alloc) stack_vars_alloc = stack_vars_alloc * 3 / 2; else stack_vars_alloc = 32; stack_vars = XRESIZEVEC (struct stack_var, stack_vars, stack_vars_alloc); } stack_vars[stack_vars_num].decl = decl; stack_vars[stack_vars_num].offset = 0; stack_vars[stack_vars_num].size = tree_low_cst (DECL_SIZE_UNIT (decl), 1); stack_vars[stack_vars_num].alignb = get_decl_align_unit (decl); /* All variables are initially in their own partition. */ stack_vars[stack_vars_num].representative = stack_vars_num; stack_vars[stack_vars_num].next = EOC; /* Ensure that this decl doesn't get put onto the list twice. */ SET_DECL_RTL (decl, pc_rtx); stack_vars_num++; } /* Compute the linear index of a lower-triangular coordinate (I, J). */ static size_t triangular_index (size_t i, size_t j) { if (i < j) { size_t t; t = i, i = j, j = t; } return (i * (i + 1)) / 2 + j; } /* Ensure that STACK_VARS_CONFLICT is large enough for N objects. */ static void resize_stack_vars_conflict (size_t n) { size_t size = triangular_index (n-1, n-1) + 1; if (size <= stack_vars_conflict_alloc) return; stack_vars_conflict = XRESIZEVEC (bool, stack_vars_conflict, size); memset (stack_vars_conflict + stack_vars_conflict_alloc, 0, (size - stack_vars_conflict_alloc) * sizeof (bool)); stack_vars_conflict_alloc = size; } /* Make the decls associated with luid's X and Y conflict. */ static void add_stack_var_conflict (size_t x, size_t y) { size_t index = triangular_index (x, y); gcc_assert (index < stack_vars_conflict_alloc); stack_vars_conflict[index] = true; } /* Check whether the decls associated with luid's X and Y conflict. */ static bool stack_var_conflict_p (size_t x, size_t y) { size_t index = triangular_index (x, y); gcc_assert (index < stack_vars_conflict_alloc); return stack_vars_conflict[index]; } /* Returns true if TYPE is or contains a union type. */ static bool aggregate_contains_union_type (tree type) { tree field; if (TREE_CODE (type) == UNION_TYPE || TREE_CODE (type) == QUAL_UNION_TYPE) return true; if (TREE_CODE (type) == ARRAY_TYPE) return aggregate_contains_union_type (TREE_TYPE (type)); if (TREE_CODE (type) != RECORD_TYPE) return false; for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field)) if (TREE_CODE (field) == FIELD_DECL) if (aggregate_contains_union_type (TREE_TYPE (field))) return true; return false; } /* A subroutine of expand_used_vars. If two variables X and Y have alias sets that do not conflict, then do add a conflict for these variables in the interference graph. We also need to make sure to add conflicts for union containing structures. Else RTL alias analysis comes along and due to type based aliasing rules decides that for two overlapping union temporaries { short s; int i; } accesses to the same mem through different types may not alias and happily reorders stores across life-time boundaries of the temporaries (See PR25654). We also have to mind MEM_IN_STRUCT_P and MEM_SCALAR_P. */ static void add_alias_set_conflicts (void) { size_t i, j, n = stack_vars_num; for (i = 0; i < n; ++i) { tree type_i = TREE_TYPE (stack_vars[i].decl); bool aggr_i = AGGREGATE_TYPE_P (type_i); bool contains_union; contains_union = aggregate_contains_union_type (type_i); for (j = 0; j < i; ++j) { tree type_j = TREE_TYPE (stack_vars[j].decl); bool aggr_j = AGGREGATE_TYPE_P (type_j); if (aggr_i != aggr_j /* Either the objects conflict by means of type based aliasing rules, or we need to add a conflict. */ || !objects_must_conflict_p (type_i, type_j) /* In case the types do not conflict ensure that access to elements will conflict. In case of unions we have to be careful as type based aliasing rules may say access to the same memory does not conflict. So play safe and add a conflict in this case. */ || contains_union) add_stack_var_conflict (i, j); } } } /* A subroutine of partition_stack_vars. A comparison function for qsort, sorting an array of indicies by the size of the object. */ static int stack_var_size_cmp (const void *a, const void *b) { HOST_WIDE_INT sa = stack_vars[*(const size_t *)a].size; HOST_WIDE_INT sb = stack_vars[*(const size_t *)b].size; unsigned int uida = DECL_UID (stack_vars[*(const size_t *)a].decl); unsigned int uidb = DECL_UID (stack_vars[*(const size_t *)b].decl); if (sa < sb) return -1; if (sa > sb) return 1; /* For stack variables of the same size use the uid of the decl to make the sort stable. */ if (uida < uidb) return -1; if (uida > uidb) return 1; return 0; } /* A subroutine of partition_stack_vars. The UNION portion of a UNION/FIND partitioning algorithm. Partitions A and B are known to be non-conflicting. Merge them into a single partition A. At the same time, add OFFSET to all variables in partition B. At the end of the partitioning process we've have a nice block easy to lay out within the stack frame. */ static void union_stack_vars (size_t a, size_t b, HOST_WIDE_INT offset) { size_t i, last; /* Update each element of partition B with the given offset, and merge them into partition A. */ for (last = i = b; i != EOC; last = i, i = stack_vars[i].next) { stack_vars[i].offset += offset; stack_vars[i].representative = a; } stack_vars[last].next = stack_vars[a].next; stack_vars[a].next = b; /* Update the required alignment of partition A to account for B. */ if (stack_vars[a].alignb < stack_vars[b].alignb) stack_vars[a].alignb = stack_vars[b].alignb; /* Update the interference graph and merge the conflicts. */ for (last = stack_vars_num, i = 0; i < last; ++i) if (stack_var_conflict_p (b, i)) add_stack_var_conflict (a, i); } /* A subroutine of expand_used_vars. Binpack the variables into partitions constrained by the interference graph. The overall algorithm used is as follows: Sort the objects by size. For each object A { S = size(A) O = 0 loop { Look for the largest non-conflicting object B with size <= S. UNION (A, B) offset(B) = O O += size(B) S -= size(B) } } */ static void partition_stack_vars (void) { size_t si, sj, n = stack_vars_num; stack_vars_sorted = XNEWVEC (size_t, stack_vars_num); for (si = 0; si < n; ++si) stack_vars_sorted[si] = si; if (n == 1) return; qsort (stack_vars_sorted, n, sizeof (size_t), stack_var_size_cmp); /* Special case: detect when all variables conflict, and thus we can't do anything during the partitioning loop. It isn't uncommon (with C code at least) to declare all variables at the top of the function, and if we're not inlining, then all variables will be in the same scope. Take advantage of very fast libc routines for this scan. */ gcc_assert (sizeof(bool) == sizeof(char)); if (memchr (stack_vars_conflict, false, stack_vars_conflict_alloc) == NULL) return; for (si = 0; si < n; ++si) { size_t i = stack_vars_sorted[si]; HOST_WIDE_INT isize = stack_vars[i].size; HOST_WIDE_INT offset = 0; for (sj = si; sj-- > 0; ) { size_t j = stack_vars_sorted[sj]; HOST_WIDE_INT jsize = stack_vars[j].size; unsigned int jalign = stack_vars[j].alignb; /* Ignore objects that aren't partition representatives. */ if (stack_vars[j].representative != j) continue; /* Ignore objects too large for the remaining space. */ if (isize < jsize) continue; /* Ignore conflicting objects. */ if (stack_var_conflict_p (i, j)) continue; /* Refine the remaining space check to include alignment. */ if (offset & (jalign - 1)) { HOST_WIDE_INT toff = offset; toff += jalign - 1; toff &= -(HOST_WIDE_INT)jalign; if (isize - (toff - offset) < jsize) continue; isize -= toff - offset; offset = toff; } /* UNION the objects, placing J at OFFSET. */ union_stack_vars (i, j, offset); isize -= jsize; if (isize == 0) break; } } } /* A debugging aid for expand_used_vars. Dump the generated partitions. */ static void dump_stack_var_partition (void) { size_t si, i, j, n = stack_vars_num; for (si = 0; si < n; ++si) { i = stack_vars_sorted[si]; /* Skip variables that aren't partition representatives, for now. */ if (stack_vars[i].representative != i) continue; fprintf (dump_file, "Partition %lu: size " HOST_WIDE_INT_PRINT_DEC " align %u\n", (unsigned long) i, stack_vars[i].size, stack_vars[i].alignb); for (j = i; j != EOC; j = stack_vars[j].next) { fputc ('\t', dump_file); print_generic_expr (dump_file, stack_vars[j].decl, dump_flags); fprintf (dump_file, ", offset " HOST_WIDE_INT_PRINT_DEC "\n", stack_vars[i].offset); } } } /* Assign rtl to DECL at frame offset OFFSET. */ static void expand_one_stack_var_at (tree decl, HOST_WIDE_INT offset) { HOST_WIDE_INT align; rtx x; /* If this fails, we've overflowed the stack frame. Error nicely? */ gcc_assert (offset == trunc_int_for_mode (offset, Pmode)); x = plus_constant (virtual_stack_vars_rtx, offset); x = gen_rtx_MEM (DECL_MODE (decl), x); /* Set alignment we actually gave this decl. */ offset -= frame_phase; align = offset & -offset; align *= BITS_PER_UNIT; if (align > STACK_BOUNDARY || align == 0) align = STACK_BOUNDARY; DECL_ALIGN (decl) = align; DECL_USER_ALIGN (decl) = 0; set_mem_attributes (x, decl, true); SET_DECL_RTL (decl, x); } /* A subroutine of expand_used_vars. Give each partition representative a unique location within the stack frame. Update each partition member with that location. */ static void expand_stack_vars (bool (*pred) (tree)) { size_t si, i, j, n = stack_vars_num; for (si = 0; si < n; ++si) { HOST_WIDE_INT offset; i = stack_vars_sorted[si]; /* Skip variables that aren't partition representatives, for now. */ if (stack_vars[i].representative != i) continue; /* Skip variables that have already had rtl assigned. See also add_stack_var where we perpetrate this pc_rtx hack. */ if (DECL_RTL (stack_vars[i].decl) != pc_rtx) continue; /* Check the predicate to see whether this variable should be allocated in this pass. */ if (pred && !pred (stack_vars[i].decl)) continue; offset = alloc_stack_frame_space (stack_vars[i].size, stack_vars[i].alignb); /* Create rtl for each variable based on their location within the partition. */ for (j = i; j != EOC; j = stack_vars[j].next) expand_one_stack_var_at (stack_vars[j].decl, stack_vars[j].offset + offset); } } /* A subroutine of expand_one_var. Called to immediately assign rtl to a variable to be allocated in the stack frame. */ static void expand_one_stack_var (tree var) { HOST_WIDE_INT size, offset, align; size = tree_low_cst (DECL_SIZE_UNIT (var), 1); align = get_decl_align_unit (var); offset = alloc_stack_frame_space (size, align); expand_one_stack_var_at (var, offset); } /* A subroutine of expand_one_var. Called to assign rtl to a TREE_STATIC VAR_DECL. */ static void expand_one_static_var (tree var) { /* In unit-at-a-time all the static variables are expanded at the end of compilation process. */ if (flag_unit_at_a_time) return; /* If this is an inlined copy of a static local variable, look up the original. */ var = DECL_ORIGIN (var); /* If we've already processed this variable because of that, do nothing. */ if (TREE_ASM_WRITTEN (var)) return; /* Give the front end a chance to do whatever. In practice, this is resolving duplicate names for IMA in C. */ if (lang_hooks.expand_decl (var)) return; /* Otherwise, just emit the variable. */ rest_of_decl_compilation (var, 0, 0); } /* A subroutine of expand_one_var. Called to assign rtl to a VAR_DECL that will reside in a hard register. */ static void expand_one_hard_reg_var (tree var) { rest_of_decl_compilation (var, 0, 0); } /* A subroutine of expand_one_var. Called to assign rtl to a VAR_DECL that will reside in a pseudo register. */ static void expand_one_register_var (tree var) { tree type = TREE_TYPE (var); int unsignedp = TYPE_UNSIGNED (type); enum machine_mode reg_mode = promote_mode (type, DECL_MODE (var), &unsignedp, 0); rtx x = gen_reg_rtx (reg_mode); SET_DECL_RTL (var, x); /* Note if the object is a user variable. */ if (!DECL_ARTIFICIAL (var)) { mark_user_reg (x); /* Trust user variables which have a pointer type to really be pointers. Do not trust compiler generated temporaries as our type system is totally busted as it relates to pointer arithmetic which translates into lots of compiler generated objects with pointer types, but which are not really pointers. */ if (POINTER_TYPE_P (type)) mark_reg_pointer (x, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (var)))); } } /* A subroutine of expand_one_var. Called to assign rtl to a VAR_DECL that has some associated error, e.g. its type is error-mark. We just need to pick something that won't crash the rest of the compiler. */ static void expand_one_error_var (tree var) { enum machine_mode mode = DECL_MODE (var); rtx x; if (mode == BLKmode) x = gen_rtx_MEM (BLKmode, const0_rtx); else if (mode == VOIDmode) x = const0_rtx; else x = gen_reg_rtx (mode); SET_DECL_RTL (var, x); } /* A subroutine of expand_one_var. VAR is a variable that will be allocated to the local stack frame. Return true if we wish to add VAR to STACK_VARS so that it will be coalesced with other variables. Return false to allocate VAR immediately. This function is used to reduce the number of variables considered for coalescing, which reduces the size of the quadratic problem. */ static bool defer_stack_allocation (tree var, bool toplevel) { /* If stack protection is enabled, *all* stack variables must be deferred, so that we can re-order the strings to the top of the frame. */ if (flag_stack_protect) return true; /* Variables in the outermost scope automatically conflict with every other variable. The only reason to want to defer them at all is that, after sorting, we can more efficiently pack small variables in the stack frame. Continue to defer at -O2. */ if (toplevel && optimize < 2) return false; /* Without optimization, *most* variables are allocated from the stack, which makes the quadratic problem large exactly when we want compilation to proceed as quickly as possible. On the other hand, we don't want the function's stack frame size to get completely out of hand. So we avoid adding scalars and "small" aggregates to the list at all. */ if (optimize == 0 && tree_low_cst (DECL_SIZE_UNIT (var), 1) < 32) return false; return true; } /* A subroutine of expand_used_vars. Expand one variable according to its flavor. Variables to be placed on the stack are not actually expanded yet, merely recorded. */ static void expand_one_var (tree var, bool toplevel) { if (TREE_CODE (var) != VAR_DECL) lang_hooks.expand_decl (var); else if (DECL_EXTERNAL (var)) ; else if (DECL_HAS_VALUE_EXPR_P (var)) ; else if (TREE_STATIC (var)) expand_one_static_var (var); else if (DECL_RTL_SET_P (var)) ; else if (TREE_TYPE (var) == error_mark_node) expand_one_error_var (var); else if (DECL_HARD_REGISTER (var)) expand_one_hard_reg_var (var); else if (use_register_for_decl (var)) expand_one_register_var (var); else if (defer_stack_allocation (var, toplevel)) add_stack_var (var); else expand_one_stack_var (var); } /* A subroutine of expand_used_vars. Walk down through the BLOCK tree expanding variables. Those variables that can be put into registers are allocated pseudos; those that can't are put on the stack. TOPLEVEL is true if this is the outermost BLOCK. */ static void expand_used_vars_for_block (tree block, bool toplevel) { size_t i, j, old_sv_num, this_sv_num, new_sv_num; tree t; old_sv_num = toplevel ? 0 : stack_vars_num; /* Expand all variables at this level. */ for (t = BLOCK_VARS (block); t ; t = TREE_CHAIN (t)) if (TREE_USED (t) /* Force local static variables to be output when marked by used attribute. For unit-at-a-time, cgraph code already takes care of this. */ || (!flag_unit_at_a_time && TREE_STATIC (t) && DECL_PRESERVE_P (t))) expand_one_var (t, toplevel); this_sv_num = stack_vars_num; /* Expand all variables at containing levels. */ for (t = BLOCK_SUBBLOCKS (block); t ; t = BLOCK_CHAIN (t)) expand_used_vars_for_block (t, false); /* Since we do not track exact variable lifetimes (which is not even possible for variables whose address escapes), we mirror the block tree in the interference graph. Here we cause all variables at this level, and all sublevels, to conflict. Do make certain that a variable conflicts with itself. */ if (old_sv_num < this_sv_num) { new_sv_num = stack_vars_num; resize_stack_vars_conflict (new_sv_num); for (i = old_sv_num; i < new_sv_num; ++i) for (j = i < this_sv_num ? i+1 : this_sv_num; j-- > old_sv_num ;) add_stack_var_conflict (i, j); } } /* A subroutine of expand_used_vars. Walk down through the BLOCK tree and clear TREE_USED on all local variables. */ static void clear_tree_used (tree block) { tree t; for (t = BLOCK_VARS (block); t ; t = TREE_CHAIN (t)) /* if (!TREE_STATIC (t) && !DECL_EXTERNAL (t)) */ TREE_USED (t) = 0; for (t = BLOCK_SUBBLOCKS (block); t ; t = BLOCK_CHAIN (t)) clear_tree_used (t); } +enum { + SPCT_FLAG_DEFAULT = 1, + SPCT_FLAG_ALL = 2, + SPCT_FLAG_STRONG = 3 +}; + /* Examine TYPE and determine a bit mask of the following features. */ #define SPCT_HAS_LARGE_CHAR_ARRAY 1 #define SPCT_HAS_SMALL_CHAR_ARRAY 2 #define SPCT_HAS_ARRAY 4 #define SPCT_HAS_AGGREGATE 8 static unsigned int stack_protect_classify_type (tree type) { unsigned int ret = 0; tree t; switch (TREE_CODE (type)) { case ARRAY_TYPE: t = TYPE_MAIN_VARIANT (TREE_TYPE (type)); if (t == char_type_node || t == signed_char_type_node || t == unsigned_char_type_node) { unsigned HOST_WIDE_INT max = PARAM_VALUE (PARAM_SSP_BUFFER_SIZE); unsigned HOST_WIDE_INT len; if (!TYPE_SIZE_UNIT (type) || !host_integerp (TYPE_SIZE_UNIT (type), 1)) len = max; else len = tree_low_cst (TYPE_SIZE_UNIT (type), 1); if (len < max) ret = SPCT_HAS_SMALL_CHAR_ARRAY | SPCT_HAS_ARRAY; else ret = SPCT_HAS_LARGE_CHAR_ARRAY | SPCT_HAS_ARRAY; } else ret = SPCT_HAS_ARRAY; break; case UNION_TYPE: case QUAL_UNION_TYPE: case RECORD_TYPE: ret = SPCT_HAS_AGGREGATE; for (t = TYPE_FIELDS (type); t ; t = TREE_CHAIN (t)) if (TREE_CODE (t) == FIELD_DECL) ret |= stack_protect_classify_type (TREE_TYPE (t)); break; default: break; } return ret; } /* Return nonzero if DECL should be segregated into the "vulnerable" upper part of the local stack frame. Remember if we ever return nonzero for any variable in this function. The return value is the phase number in which the variable should be allocated. */ static int stack_protect_decl_phase (tree decl) { unsigned int bits = stack_protect_classify_type (TREE_TYPE (decl)); int ret = 0; if (bits & SPCT_HAS_SMALL_CHAR_ARRAY) has_short_buffer = true; - if (flag_stack_protect == 2) + if (flag_stack_protect == SPCT_FLAG_ALL + || flag_stack_protect == SPCT_FLAG_STRONG) { if ((bits & (SPCT_HAS_SMALL_CHAR_ARRAY | SPCT_HAS_LARGE_CHAR_ARRAY)) && !(bits & SPCT_HAS_AGGREGATE)) ret = 1; else if (bits & SPCT_HAS_ARRAY) ret = 2; } else ret = (bits & SPCT_HAS_LARGE_CHAR_ARRAY) != 0; if (ret) has_protected_decls = true; return ret; } /* Two helper routines that check for phase 1 and phase 2. These are used as callbacks for expand_stack_vars. */ static bool stack_protect_decl_phase_1 (tree decl) { return stack_protect_decl_phase (decl) == 1; } static bool stack_protect_decl_phase_2 (tree decl) { return stack_protect_decl_phase (decl) == 2; } /* Ensure that variables in different stack protection phases conflict so that they are not merged and share the same stack slot. */ static void add_stack_protection_conflicts (void) { size_t i, j, n = stack_vars_num; unsigned char *phase; phase = XNEWVEC (unsigned char, n); for (i = 0; i < n; ++i) phase[i] = stack_protect_decl_phase (stack_vars[i].decl); for (i = 0; i < n; ++i) { unsigned char ph_i = phase[i]; for (j = 0; j < i; ++j) if (ph_i != phase[j]) add_stack_var_conflict (i, j); } XDELETEVEC (phase); } /* Create a decl for the guard at the top of the stack frame. */ static void create_stack_guard (void) { tree guard = build_decl (VAR_DECL, NULL, ptr_type_node); TREE_THIS_VOLATILE (guard) = 1; TREE_USED (guard) = 1; expand_one_stack_var (guard); cfun->stack_protect_guard = guard; } +/* Helper routine to check if a record or union contains an array field. */ + +static int +record_or_union_type_has_array_p (tree tree_type) +{ + tree fields = TYPE_FIELDS (tree_type); + tree f; + + for (f = fields; f; f = TREE_CHAIN (f)) + if (TREE_CODE (f) == FIELD_DECL) + { + tree field_type = TREE_TYPE (f); + if ((TREE_CODE (field_type) == RECORD_TYPE + || TREE_CODE (field_type) == UNION_TYPE + || TREE_CODE (field_type) == QUAL_UNION_TYPE) + && record_or_union_type_has_array_p (field_type)) + return 1; + if (TREE_CODE (field_type) == ARRAY_TYPE) + return 1; + } + return 0; +} + /* Expand all variables used in the function. */ static void expand_used_vars (void) { tree t, outer_block = DECL_INITIAL (current_function_decl); + bool gen_stack_protect_signal = false; /* Compute the phase of the stack frame for this function. */ { int align = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT; int off = STARTING_FRAME_OFFSET % align; frame_phase = off ? align - off : 0; } /* Set TREE_USED on all variables in the unexpanded_var_list. */ for (t = cfun->unexpanded_var_list; t; t = TREE_CHAIN (t)) TREE_USED (TREE_VALUE (t)) = 1; /* Clear TREE_USED on all variables associated with a block scope. */ clear_tree_used (outer_block); /* Initialize local stack smashing state. */ has_protected_decls = false; has_short_buffer = false; + if (flag_stack_protect == SPCT_FLAG_STRONG) + for (t = cfun->unexpanded_var_list; t; t = TREE_CHAIN (t)) + { + tree var = TREE_VALUE (t); + if (!is_global_var (var)) + { + tree var_type = TREE_TYPE (var); + /* Examine local referenced variables that have their addresses + * taken, contain an array, or are arrays. */ + if (TREE_CODE (var) == VAR_DECL + && (TREE_CODE (var_type) == ARRAY_TYPE + || TREE_ADDRESSABLE (var) + || ((TREE_CODE (var_type) == RECORD_TYPE + || TREE_CODE (var_type) == UNION_TYPE + || TREE_CODE (var_type) == QUAL_UNION_TYPE) + && record_or_union_type_has_array_p (var_type)))) + { + gen_stack_protect_signal = true; + break; + } + } + } + /* At this point all variables on the unexpanded_var_list with TREE_USED set are not associated with any block scope. Lay them out. */ for (t = cfun->unexpanded_var_list; t; t = TREE_CHAIN (t)) { tree var = TREE_VALUE (t); bool expand_now = false; /* We didn't set a block for static or extern because it's hard to tell the difference between a global variable (re)declared in a local scope, and one that's really declared there to begin with. And it doesn't really matter much, since we're not giving them stack space. Expand them now. */ if (TREE_STATIC (var) || DECL_EXTERNAL (var)) expand_now = true; /* Any variable that could have been hoisted into an SSA_NAME will have been propagated anywhere the optimizers chose, i.e. not confined to their original block. Allocate them as if they were defined in the outermost scope. */ else if (is_gimple_reg (var)) expand_now = true; /* If the variable is not associated with any block, then it was created by the optimizers, and could be live anywhere in the function. */ else if (TREE_USED (var)) expand_now = true; /* Finally, mark all variables on the list as used. We'll use this in a moment when we expand those associated with scopes. */ TREE_USED (var) = 1; if (expand_now) expand_one_var (var, true); } cfun->unexpanded_var_list = NULL_TREE; /* At this point, all variables within the block tree with TREE_USED set are actually used by the optimized function. Lay them out. */ expand_used_vars_for_block (outer_block, true); if (stack_vars_num > 0) { /* Due to the way alias sets work, no variables with non-conflicting alias sets may be assigned the same address. Add conflicts to reflect this. */ add_alias_set_conflicts (); /* If stack protection is enabled, we don't share space between vulnerable data and non-vulnerable data. */ if (flag_stack_protect) add_stack_protection_conflicts (); /* Now that we have collected all stack variables, and have computed a minimal interference graph, attempt to save some stack space. */ partition_stack_vars (); if (dump_file) dump_stack_var_partition (); } - /* There are several conditions under which we should create a - stack guard: protect-all, alloca used, protected decls present. */ - if (flag_stack_protect == 2 - || (flag_stack_protect - && (current_function_calls_alloca || has_protected_decls))) - create_stack_guard (); + switch (flag_stack_protect) + { + case SPCT_FLAG_ALL: + create_stack_guard (); + break; + + case SPCT_FLAG_STRONG: + if (gen_stack_protect_signal + || current_function_calls_alloca || has_protected_decls) + create_stack_guard (); + break; + + case SPCT_FLAG_DEFAULT: + if (current_function_calls_alloca || has_protected_decls) + create_stack_guard(); + break; + + default: + ; + } /* Assign rtl to each variable based on these partitions. */ if (stack_vars_num > 0) { /* Reorder decls to be protected by iterating over the variables array multiple times, and allocating out of each phase in turn. */ /* ??? We could probably integrate this into the qsort we did earlier, such that we naturally see these variables first, and thus naturally allocate things in the right order. */ if (has_protected_decls) { /* Phase 1 contains only character arrays. */ expand_stack_vars (stack_protect_decl_phase_1); /* Phase 2 contains other kinds of arrays. */ if (flag_stack_protect == 2) expand_stack_vars (stack_protect_decl_phase_2); } expand_stack_vars (NULL); /* Free up stack variable graph data. */ XDELETEVEC (stack_vars); XDELETEVEC (stack_vars_sorted); XDELETEVEC (stack_vars_conflict); stack_vars = NULL; stack_vars_alloc = stack_vars_num = 0; stack_vars_conflict = NULL; stack_vars_conflict_alloc = 0; } /* If the target requires that FRAME_OFFSET be aligned, do it. */ if (STACK_ALIGNMENT_NEEDED) { HOST_WIDE_INT align = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT; if (!FRAME_GROWS_DOWNWARD) frame_offset += align - 1; frame_offset &= -align; } } /* If we need to produce a detailed dump, print the tree representation for STMT to the dump file. SINCE is the last RTX after which the RTL generated for STMT should have been appended. */ static void maybe_dump_rtl_for_tree_stmt (tree stmt, rtx since) { if (dump_file && (dump_flags & TDF_DETAILS)) { fprintf (dump_file, "\n;; "); print_generic_expr (dump_file, stmt, TDF_SLIM); fprintf (dump_file, "\n"); print_rtl (dump_file, since ? NEXT_INSN (since) : since); } } /* A subroutine of expand_gimple_basic_block. Expand one COND_EXPR. Returns a new basic block if we've terminated the current basic block and created a new one. */ static basic_block expand_gimple_cond_expr (basic_block bb, tree stmt) { basic_block new_bb, dest; edge new_edge; edge true_edge; edge false_edge; tree pred = COND_EXPR_COND (stmt); tree then_exp = COND_EXPR_THEN (stmt); tree else_exp = COND_EXPR_ELSE (stmt); rtx last2, last; last2 = last = get_last_insn (); extract_true_false_edges_from_block (bb, &true_edge, &false_edge); if (EXPR_LOCUS (stmt)) { emit_line_note (*(EXPR_LOCUS (stmt))); record_block_change (TREE_BLOCK (stmt)); } /* These flags have no purpose in RTL land. */ true_edge->flags &= ~EDGE_TRUE_VALUE; false_edge->flags &= ~EDGE_FALSE_VALUE; /* We can either have a pure conditional jump with one fallthru edge or two-way jump that needs to be decomposed into two basic blocks. */ if (TREE_CODE (then_exp) == GOTO_EXPR && IS_EMPTY_STMT (else_exp)) { jumpif (pred, label_rtx (GOTO_DESTINATION (then_exp))); add_reg_br_prob_note (last, true_edge->probability); maybe_dump_rtl_for_tree_stmt (stmt, last); if (EXPR_LOCUS (then_exp)) emit_line_note (*(EXPR_LOCUS (then_exp))); return NULL; } if (TREE_CODE (else_exp) == GOTO_EXPR && IS_EMPTY_STMT (then_exp)) { jumpifnot (pred, label_rtx (GOTO_DESTINATION (else_exp))); add_reg_br_prob_note (last, false_edge->probability); maybe_dump_rtl_for_tree_stmt (stmt, last); if (EXPR_LOCUS (else_exp)) emit_line_note (*(EXPR_LOCUS (else_exp))); return NULL; } gcc_assert (TREE_CODE (then_exp) == GOTO_EXPR && TREE_CODE (else_exp) == GOTO_EXPR); jumpif (pred, label_rtx (GOTO_DESTINATION (then_exp))); add_reg_br_prob_note (last, true_edge->probability); last = get_last_insn (); expand_expr (else_exp, const0_rtx, VOIDmode, 0); BB_END (bb) = last; if (BARRIER_P (BB_END (bb))) BB_END (bb) = PREV_INSN (BB_END (bb)); update_bb_for_insn (bb); new_bb = create_basic_block (NEXT_INSN (last), get_last_insn (), bb); dest = false_edge->dest; redirect_edge_succ (false_edge, new_bb); false_edge->flags |= EDGE_FALLTHRU; new_bb->count = false_edge->count; new_bb->frequency = EDGE_FREQUENCY (false_edge); new_edge = make_edge (new_bb, dest, 0); new_edge->probability = REG_BR_PROB_BASE; new_edge->count = new_bb->count; if (BARRIER_P (BB_END (new_bb))) BB_END (new_bb) = PREV_INSN (BB_END (new_bb)); update_bb_for_insn (new_bb); maybe_dump_rtl_for_tree_stmt (stmt, last2); if (EXPR_LOCUS (else_exp)) emit_line_note (*(EXPR_LOCUS (else_exp))); return new_bb; } /* A subroutine of expand_gimple_basic_block. Expand one CALL_EXPR that has CALL_EXPR_TAILCALL set. Returns non-null if we actually generated a tail call (something that might be denied by the ABI rules governing the call; see calls.c). Sets CAN_FALLTHRU if we generated a *conditional* tail call, and can still reach the rest of BB. The case here is __builtin_sqrt, where the NaN result goes through the external function (with a tailcall) and the normal result happens via a sqrt instruction. */ static basic_block expand_gimple_tailcall (basic_block bb, tree stmt, bool *can_fallthru) { rtx last2, last; edge e; edge_iterator ei; int probability; gcov_type count; last2 = last = get_last_insn (); expand_expr_stmt (stmt); for (last = NEXT_INSN (last); last; last = NEXT_INSN (last)) if (CALL_P (last) && SIBLING_CALL_P (last)) goto found; maybe_dump_rtl_for_tree_stmt (stmt, last2); *can_fallthru = true; return NULL; found: /* ??? Wouldn't it be better to just reset any pending stack adjust? Any instructions emitted here are about to be deleted. */ do_pending_stack_adjust (); /* Remove any non-eh, non-abnormal edges that don't go to exit. */ /* ??? I.e. the fallthrough edge. HOWEVER! If there were to be EH or abnormal edges, we shouldn't have created a tail call in the first place. So it seems to me we should just be removing all edges here, or redirecting the existing fallthru edge to the exit block. */ probability = 0; count = 0; for (ei = ei_start (bb->succs); (e = ei_safe_edge (ei)); ) { if (!(e->flags & (EDGE_ABNORMAL | EDGE_EH))) { if (e->dest != EXIT_BLOCK_PTR) { e->dest->count -= e->count; e->dest->frequency -= EDGE_FREQUENCY (e); if (e->dest->count < 0) e->dest->count = 0; if (e->dest->frequency < 0) e->dest->frequency = 0; } count += e->count; probability += e->probability; remove_edge (e); } else ei_next (&ei); } /* This is somewhat ugly: the call_expr expander often emits instructions after the sibcall (to perform the function return). These confuse the find_many_sub_basic_blocks code, so we need to get rid of these. */ last = NEXT_INSN (last); gcc_assert (BARRIER_P (last)); *can_fallthru = false; while (NEXT_INSN (last)) { /* For instance an sqrt builtin expander expands if with sibcall in the then and label for `else`. */ if (LABEL_P (NEXT_INSN (last))) { *can_fallthru = true; break; } delete_insn (NEXT_INSN (last)); } e = make_edge (bb, EXIT_BLOCK_PTR, EDGE_ABNORMAL | EDGE_SIBCALL); e->probability += probability; e->count += count; BB_END (bb) = last; update_bb_for_insn (bb); if (NEXT_INSN (last)) { bb = create_basic_block (NEXT_INSN (last), get_last_insn (), bb); last = BB_END (bb); if (BARRIER_P (last)) BB_END (bb) = PREV_INSN (last); } maybe_dump_rtl_for_tree_stmt (stmt, last2); return bb; } /* Expand basic block BB from GIMPLE trees to RTL. */ static basic_block expand_gimple_basic_block (basic_block bb) { block_stmt_iterator bsi = bsi_start (bb); tree stmt = NULL; rtx note, last; edge e; edge_iterator ei; if (dump_file) { fprintf (dump_file, "\n;; Generating RTL for tree basic block %d\n", bb->index); } init_rtl_bb_info (bb); bb->flags |= BB_RTL; if (!bsi_end_p (bsi)) stmt = bsi_stmt (bsi); if (stmt && TREE_CODE (stmt) == LABEL_EXPR) { last = get_last_insn (); expand_expr_stmt (stmt); /* Java emits line number notes in the top of labels. ??? Make this go away once line number notes are obsoleted. */ BB_HEAD (bb) = NEXT_INSN (last); if (NOTE_P (BB_HEAD (bb))) BB_HEAD (bb) = NEXT_INSN (BB_HEAD (bb)); bsi_next (&bsi); note = emit_note_after (NOTE_INSN_BASIC_BLOCK, BB_HEAD (bb)); maybe_dump_rtl_for_tree_stmt (stmt, last); } else note = BB_HEAD (bb) = emit_note (NOTE_INSN_BASIC_BLOCK); NOTE_BASIC_BLOCK (note) = bb; for (ei = ei_start (bb->succs); (e = ei_safe_edge (ei)); ) { /* Clear EDGE_EXECUTABLE. This flag is never used in the backend. */ e->flags &= ~EDGE_EXECUTABLE; /* At the moment not all abnormal edges match the RTL representation. It is safe to remove them here as find_many_sub_basic_blocks will rediscover them. In the future we should get this fixed properly. */ if (e->flags & EDGE_ABNORMAL) remove_edge (e); else ei_next (&ei); } for (; !bsi_end_p (bsi); bsi_next (&bsi)) { tree stmt = bsi_stmt (bsi); basic_block new_bb; if (!stmt) continue; /* Expand this statement, then evaluate the resulting RTL and fixup the CFG accordingly. */ if (TREE_CODE (stmt) == COND_EXPR) { new_bb = expand_gimple_cond_expr (bb, stmt); if (new_bb) return new_bb; } else { tree call = get_call_expr_in (stmt); if (call && CALL_EXPR_TAILCALL (call)) { bool can_fallthru; new_bb = expand_gimple_tailcall (bb, stmt, &can_fallthru); if (new_bb) { if (can_fallthru) bb = new_bb; else return new_bb; } } else { last = get_last_insn (); expand_expr_stmt (stmt); maybe_dump_rtl_for_tree_stmt (stmt, last); } } } do_pending_stack_adjust (); /* Find the block tail. The last insn in the block is the insn before a barrier and/or table jump insn. */ last = get_last_insn (); if (BARRIER_P (last)) last = PREV_INSN (last); if (JUMP_TABLE_DATA_P (last)) last = PREV_INSN (PREV_INSN (last)); BB_END (bb) = last; update_bb_for_insn (bb); return bb; } /* Create a basic block for initialization code. */ static basic_block construct_init_block (void) { basic_block init_block, first_block; edge e = NULL; int flags; /* Multiple entry points not supported yet. */ gcc_assert (EDGE_COUNT (ENTRY_BLOCK_PTR->succs) == 1); init_rtl_bb_info (ENTRY_BLOCK_PTR); init_rtl_bb_info (EXIT_BLOCK_PTR); ENTRY_BLOCK_PTR->flags |= BB_RTL; EXIT_BLOCK_PTR->flags |= BB_RTL; e = EDGE_SUCC (ENTRY_BLOCK_PTR, 0); /* When entry edge points to first basic block, we don't need jump, otherwise we have to jump into proper target. */ if (e && e->dest != ENTRY_BLOCK_PTR->next_bb) { tree label = tree_block_label (e->dest); emit_jump (label_rtx (label)); flags = 0; } else flags = EDGE_FALLTHRU; init_block = create_basic_block (NEXT_INSN (get_insns ()), get_last_insn (), ENTRY_BLOCK_PTR); init_block->frequency = ENTRY_BLOCK_PTR->frequency; init_block->count = ENTRY_BLOCK_PTR->count; if (e) { first_block = e->dest; redirect_edge_succ (e, init_block); e = make_edge (init_block, first_block, flags); } else e = make_edge (init_block, EXIT_BLOCK_PTR, EDGE_FALLTHRU); e->probability = REG_BR_PROB_BASE; e->count = ENTRY_BLOCK_PTR->count; update_bb_for_insn (init_block); return init_block; } /* Create a block containing landing pads and similar stuff. */ static void construct_exit_block (void) { rtx head = get_last_insn (); rtx end; basic_block exit_block; edge e, e2; unsigned ix; edge_iterator ei; /* Make sure the locus is set to the end of the function, so that epilogue line numbers and warnings are set properly. */ #ifdef USE_MAPPED_LOCATION if (cfun->function_end_locus != UNKNOWN_LOCATION) #else if (cfun->function_end_locus.file) #endif input_location = cfun->function_end_locus; /* The following insns belong to the top scope. */ record_block_change (DECL_INITIAL (current_function_decl)); /* Generate rtl for function exit. */ expand_function_end (); end = get_last_insn (); if (head == end) return; while (NEXT_INSN (head) && NOTE_P (NEXT_INSN (head))) head = NEXT_INSN (head); exit_block = create_basic_block (NEXT_INSN (head), end, EXIT_BLOCK_PTR->prev_bb); exit_block->frequency = EXIT_BLOCK_PTR->frequency; exit_block->count = EXIT_BLOCK_PTR->count; ix = 0; while (ix < EDGE_COUNT (EXIT_BLOCK_PTR->preds)) { e = EDGE_PRED (EXIT_BLOCK_PTR, ix); if (!(e->flags & EDGE_ABNORMAL)) redirect_edge_succ (e, exit_block); else ix++; } e = make_edge (exit_block, EXIT_BLOCK_PTR, EDGE_FALLTHRU); e->probability = REG_BR_PROB_BASE; e->count = EXIT_BLOCK_PTR->count; FOR_EACH_EDGE (e2, ei, EXIT_BLOCK_PTR->preds) if (e2 != e) { e->count -= e2->count; exit_block->count -= e2->count; exit_block->frequency -= EDGE_FREQUENCY (e2); } if (e->count < 0) e->count = 0; if (exit_block->count < 0) exit_block->count = 0; if (exit_block->frequency < 0) exit_block->frequency = 0; update_bb_for_insn (exit_block); } /* Helper function for discover_nonconstant_array_refs. Look for ARRAY_REF nodes with non-constant indexes and mark them addressable. */ static tree discover_nonconstant_array_refs_r (tree * tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED) { tree t = *tp; if (IS_TYPE_OR_DECL_P (t)) *walk_subtrees = 0; else if (TREE_CODE (t) == ARRAY_REF || TREE_CODE (t) == ARRAY_RANGE_REF) { while (((TREE_CODE (t) == ARRAY_REF || TREE_CODE (t) == ARRAY_RANGE_REF) && is_gimple_min_invariant (TREE_OPERAND (t, 1)) && (!TREE_OPERAND (t, 2) || is_gimple_min_invariant (TREE_OPERAND (t, 2)))) || (TREE_CODE (t) == COMPONENT_REF && (!TREE_OPERAND (t,2) || is_gimple_min_invariant (TREE_OPERAND (t, 2)))) || TREE_CODE (t) == BIT_FIELD_REF || TREE_CODE (t) == REALPART_EXPR || TREE_CODE (t) == IMAGPART_EXPR || TREE_CODE (t) == VIEW_CONVERT_EXPR || TREE_CODE (t) == NOP_EXPR || TREE_CODE (t) == CONVERT_EXPR) t = TREE_OPERAND (t, 0); if (TREE_CODE (t) == ARRAY_REF || TREE_CODE (t) == ARRAY_RANGE_REF) { t = get_base_address (t); if (t && DECL_P (t)) TREE_ADDRESSABLE (t) = 1; } *walk_subtrees = 0; } return NULL_TREE; } /* RTL expansion is not able to compile array references with variable offsets for arrays stored in single register. Discover such expressions and mark variables as addressable to avoid this scenario. */ static void discover_nonconstant_array_refs (void) { basic_block bb; block_stmt_iterator bsi; FOR_EACH_BB (bb) { for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi)) walk_tree (bsi_stmt_ptr (bsi), discover_nonconstant_array_refs_r, NULL , NULL); } } /* Translate the intermediate representation contained in the CFG from GIMPLE trees to RTL. We do conversion per basic block and preserve/update the tree CFG. This implies we have to do some magic as the CFG can simultaneously consist of basic blocks containing RTL and GIMPLE trees. This can confuse the CFG hooks, so be careful to not manipulate CFG during the expansion. */ static unsigned int tree_expand_cfg (void) { basic_block bb, init_block; sbitmap blocks; edge_iterator ei; edge e; /* Some backends want to know that we are expanding to RTL. */ currently_expanding_to_rtl = 1; /* Prepare the rtl middle end to start recording block changes. */ reset_block_changes (); /* Mark arrays indexed with non-constant indices with TREE_ADDRESSABLE. */ discover_nonconstant_array_refs (); /* Expand the variables recorded during gimple lowering. */ expand_used_vars (); /* Honor stack protection warnings. */ if (warn_stack_protect) { if (current_function_calls_alloca) warning (0, "not protecting local variables: variable length buffer"); if (has_short_buffer && !cfun->stack_protect_guard) warning (0, "not protecting function: no buffer at least %d bytes long", (int) PARAM_VALUE (PARAM_SSP_BUFFER_SIZE)); } /* Set up parameters and prepare for return, for the function. */ expand_function_start (current_function_decl); /* If this function is `main', emit a call to `__main' to run global initializers, etc. */ if (DECL_NAME (current_function_decl) && MAIN_NAME_P (DECL_NAME (current_function_decl)) && DECL_FILE_SCOPE_P (current_function_decl)) expand_main_function (); /* Initialize the stack_protect_guard field. This must happen after the call to __main (if any) so that the external decl is initialized. */ if (cfun->stack_protect_guard) stack_protect_prologue (); /* Register rtl specific functions for cfg. */ rtl_register_cfg_hooks (); init_block = construct_init_block (); /* Clear EDGE_EXECUTABLE on the entry edge(s). It is cleaned from the remaining edges in expand_gimple_basic_block. */ FOR_EACH_EDGE (e, ei, ENTRY_BLOCK_PTR->succs) e->flags &= ~EDGE_EXECUTABLE; FOR_BB_BETWEEN (bb, init_block->next_bb, EXIT_BLOCK_PTR, next_bb) bb = expand_gimple_basic_block (bb); construct_exit_block (); /* We're done expanding trees to RTL. */ currently_expanding_to_rtl = 0; /* Convert tree EH labels to RTL EH labels, and clean out any unreachable EH regions. */ convert_from_eh_region_ranges (); rebuild_jump_labels (get_insns ()); find_exception_handler_labels (); blocks = sbitmap_alloc (last_basic_block); sbitmap_ones (blocks); find_many_sub_basic_blocks (blocks); purge_all_dead_edges (); sbitmap_free (blocks); compact_blocks (); #ifdef ENABLE_CHECKING verify_flow_info(); #endif /* There's no need to defer outputting this function any more; we know we want to output it. */ DECL_DEFER_OUTPUT (current_function_decl) = 0; /* Now that we're done expanding trees to RTL, we shouldn't have any more CONCATs anywhere. */ generating_concat_p = 0; finalize_block_changes (); if (dump_file) { fprintf (dump_file, "\n\n;;\n;; Full RTL generated for this function:\n;;\n"); /* And the pass manager will dump RTL for us. */ } /* If we're emitting a nested function, make sure its parent gets emitted as well. Doing otherwise confuses debug info. */ { tree parent; for (parent = DECL_CONTEXT (current_function_decl); parent != NULL_TREE; parent = get_containing_scope (parent)) if (TREE_CODE (parent) == FUNCTION_DECL) TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (parent)) = 1; } /* We are now committed to emitting code for this function. Do any preparation, such as emitting abstract debug info for the inline before it gets mangled by optimization. */ if (cgraph_function_possibly_inlined_p (current_function_decl)) (*debug_hooks->outlining_inline_function) (current_function_decl); TREE_ASM_WRITTEN (current_function_decl) = 1; /* After expanding, the return labels are no longer needed. */ return_label = NULL; naked_return_label = NULL; return 0; } struct tree_opt_pass pass_expand = { "expand", /* name */ NULL, /* gate */ tree_expand_cfg, /* execute */ NULL, /* sub */ NULL, /* next */ 0, /* static_pass_number */ TV_EXPAND, /* tv_id */ /* ??? If TER is enabled, we actually receive GENERIC. */ PROP_gimple_leh | PROP_cfg, /* properties_required */ PROP_rtl, /* properties_provided */ PROP_trees, /* properties_destroyed */ 0, /* todo_flags_start */ TODO_dump_func, /* todo_flags_finish */ 'r' /* letter */ }; Index: stable/10/contrib/gcc/common.opt =================================================================== --- stable/10/contrib/gcc/common.opt (revision 286712) +++ stable/10/contrib/gcc/common.opt (revision 286713) @@ -1,1174 +1,1178 @@ ; Options for the language- and target-independent parts of the compiler. ; Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc. ; ; This file is part of GCC. ; ; GCC is free software; you can redistribute it and/or modify it under ; the terms of the GNU General Public License as published by the Free ; Software Foundation; either version 2, or (at your option) any later ; version. ; ; GCC is distributed in the hope that it will be useful, but WITHOUT ANY ; WARRANTY; without even the implied warranty of MERCHANTABILITY or ; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ; for more details. ; ; You should have received a copy of the GNU General Public License ; along with GCC; see the file COPYING. If not, write to the Free ; Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA ; 02110-1301, USA. ; See the GCC internals manual for a description of this file's format. ; Please try to keep this file in ASCII collating order. -help Common Display this information -param Common Separate --param = Set parameter to value. See below for a complete list of parameters -target-help Common -version Common G Common Joined Separate UInteger -G Put global and static data smaller than bytes into a special section (on some targets) O Common JoinedOrMissing -O Set optimization level to Os Common Optimize for space rather than speed W Common RejectNegative This switch is deprecated; use -Wextra instead Waggregate-return Common Var(warn_aggregate_return) Warn about returning structures, unions or arrays Wattributes Common Var(warn_attributes) Init(1) Warn about inappropriate attribute usage Wcast-align Common Var(warn_cast_align) Warn about pointer casts which increase alignment Wdeprecated-declarations Common Var(warn_deprecated_decl) Init(1) Warn about uses of __attribute__((deprecated)) declarations Wdisabled-optimization Common Var(warn_disabled_optimization) Warn when an optimization pass is disabled Werror Common Var(warnings_are_errors) Treat all warnings as errors Werror= Common Joined Treat specified warning as error Wextra Common Print extra (possibly unwanted) warnings Wfatal-errors Common Var(flag_fatal_errors) Exit on the first error occurred Winline Common Var(warn_inline) Warn when an inlined function cannot be inlined Wlarger-than- Common RejectNegative Joined UInteger -Wlarger-than- Warn if an object is larger than bytes Wframe-larger-than- Common RejectNegative Joined UInteger -Wframe-larger-than- Warn if the frame size of a function is larger than bytes Wunsafe-loop-optimizations Common Var(warn_unsafe_loop_optimizations) Warn if the loop cannot be optimized due to nontrivial assumptions. Wmissing-noreturn Common Var(warn_missing_noreturn) Warn about functions which might be candidates for __attribute__((noreturn)) Woverflow Common Var(warn_overflow) Init(1) Warn about overflow in arithmetic expressions Wpacked Common Var(warn_packed) Warn when the packed attribute has no effect on struct layout Wpadded Common Var(warn_padded) Warn when padding is required to align structure members Wshadow Common Var(warn_shadow) Warn when one local variable shadows another Wstack-protector Common Var(warn_stack_protect) Warn when not issuing stack smashing protection for some reason Wstrict-aliasing Common Warn about code which might break strict aliasing rules Wstrict-aliasing= Common Joined UInteger Warn about code which might break strict aliasing rules Wstrict-overflow Common Warn about optimizations that assume that signed overflow is undefined Wstrict-overflow= Common Joined UInteger Warn about optimizations that assume that signed overflow is undefined Wswitch Common Var(warn_switch) Warn about enumerated switches, with no default, missing a case Wswitch-default Common Var(warn_switch_default) Warn about enumerated switches missing a \"default:\" statement Wswitch-enum Common Var(warn_switch_enum) Warn about all enumerated switches missing a specific case Wsystem-headers Common Var(warn_system_headers) Do not suppress warnings from system headers Wuninitialized Common Var(warn_uninitialized) Warn about uninitialized automatic variables Wunreachable-code Common Var(warn_notreached) Warn about code that will never be executed Wunused Common Enable all -Wunused- warnings Wunused-function Common Var(warn_unused_function) Warn when a function is unused Wunused-label Common Var(warn_unused_label) Warn when a label is unused Wunused-parameter Common Var(warn_unused_parameter) Warn when a function parameter is unused Wunused-value Common Var(warn_unused_value) Warn when an expression value is unused Wunused-variable Common Var(warn_unused_variable) Warn when a variable is unused Wvariable-decl Common Var(warn_variable_decl) Warn about variable-sized declarations. Wvolatile-register-var Common Var(warn_register_var) Warn when a register variable is declared volatile aux-info Common Separate -aux-info Emit declaration information into aux-info= Common Joined auxbase Common Separate auxbase-strip Common Separate d Common Joined -d Enable dumps from specific passes of the compiler dumpbase Common Separate -dumpbase Set the file basename to be used for dumps ; The version of the C++ ABI in use. The following values are allowed: ; ; 0: The version of the ABI believed most conformant with the C++ ABI ; specification. This ABI may change as bugs are discovered and fixed. ; Therefore, 0 will not necessarily indicate the same ABI in different ; versions of G++. ; ; 1: The version of the ABI first used in G++ 3.2. ; ; Additional positive integers will be assigned as new versions of ; the ABI become the default version of the ABI. fabi-version= Common Joined UInteger Var(flag_abi_version) Init(2) falign-functions Common Report Var(align_functions,0) Align the start of functions falign-functions= Common RejectNegative Joined UInteger falign-jumps Common Report Var(align_jumps,0) Align labels which are only reached by jumping falign-jumps= Common RejectNegative Joined UInteger falign-labels Common Report Var(align_labels,0) Align all labels falign-labels= Common RejectNegative Joined UInteger falign-loops Common Report Var(align_loops) Align the start of loops falign-loops= Common RejectNegative Joined UInteger ; This flag is only tested if alias checking is enabled. ; 0 if pointer arguments may alias each other. True in C. ; 1 if pointer arguments may not alias each other but may alias ; global variables. ; 2 if pointer arguments may not alias each other and may not ; alias global variables. ; 3 if pointer arguments may not alias anything. True in Fortran. ; Set by the front end. fargument-alias Common Report Var(flag_argument_noalias,0) Specify that arguments may alias each other and globals fargument-noalias Common Report Var(flag_argument_noalias,1) VarExists Assume arguments may alias globals but not each other fargument-noalias-global Common Report Var(flag_argument_noalias,2) VarExists Assume arguments alias neither each other nor globals fargument-noalias-anything Common Report Var(flag_argument_noalias,3) VarExists Assume arguments alias no other storage fasynchronous-unwind-tables Common Report Var(flag_asynchronous_unwind_tables) Generate unwind tables that are exact at each instruction boundary ; -fcheck-bounds causes gcc to generate array bounds checks. ; For C, C++ and ObjC: defaults off. ; For Java: defaults to on. ; For Fortran: defaults to off. fbounds-check Common Report Var(flag_bounds_check) Generate code to check bounds before indexing arrays fbranch-count-reg Common Report Var(flag_branch_on_count_reg) Init(1) Replace add, compare, branch with branch on count register fbranch-probabilities Common Report Var(flag_branch_probabilities) Use profiling information for branch probabilities fbranch-target-load-optimize Common Report Var(flag_branch_target_load_optimize) Perform branch target load optimization before prologue / epilogue threading fbranch-target-load-optimize2 Common Report Var(flag_branch_target_load_optimize2) Perform branch target load optimization after prologue / epilogue threading fbtr-bb-exclusive Common Report Var(flag_btr_bb_exclusive) Restrict target load migration not to re-use registers in any basic block fcall-saved- Common Joined RejectNegative -fcall-saved- Mark as being preserved across functions fcall-used- Common Joined RejectNegative -fcall-used- Mark as being corrupted by function calls ; Nonzero for -fcaller-saves: allocate values in regs that need to ; be saved across function calls, if that produces overall better code. ; Optional now, so people can test it. fcaller-saves Common Report Var(flag_caller_saves) Save registers around function calls fcommon Common Report Var(flag_no_common,0) Do not put uninitialized globals in the common section fcprop-registers Common Report Var(flag_cprop_registers) Perform a register copy-propagation optimization pass fcrossjumping Common Report Var(flag_crossjumping) Perform cross-jumping optimization fcse-follow-jumps Common Report Var(flag_cse_follow_jumps) When running CSE, follow jumps to their targets fcse-skip-blocks Common Report Var(flag_cse_skip_blocks) When running CSE, follow conditional jumps fcx-limited-range Common Report Var(flag_cx_limited_range) Omit range reduction step when performing complex division fdata-sections Common Report Var(flag_data_sections) Place data items into their own section ; Nonzero for -fdefer-pop: don't pop args after each function call ; instead save them up to pop many calls' args with one insns. fdefer-pop Common Report Var(flag_defer_pop) Defer popping functions args from stack until later fdelayed-branch Common Report Var(flag_delayed_branch) Attempt to fill delay slots of branch instructions fdelete-null-pointer-checks Common Report Var(flag_delete_null_pointer_checks) Delete useless null pointer checks fdiagnostics-show-location= Common Joined RejectNegative -fdiagnostics-show-location=[once|every-line] How often to emit source location at the beginning of line-wrapped diagnostics fdiagnostics-show-option Common Amend appropriate diagnostic messages with the command line option that controls them fdump- Common Joined RejectNegative -fdump- Dump various compiler internals to a file fdump-noaddr Common Report Var(flag_dump_noaddr) Suppress output of addresses in debugging dumps fdump-unnumbered Common Report Var(flag_dump_unnumbered) VarExists Suppress output of instruction numbers, line number notes and addresses in debugging dumps fearly-inlining Common Report Var(flag_early_inlining) Init(1) Perform early inlining feliminate-dwarf2-dups Common Report Var(flag_eliminate_dwarf2_dups) Perform DWARF2 duplicate elimination feliminate-unused-debug-symbols Common Report Var(flag_debug_only_used_symbols) Perform unused type elimination in debug info feliminate-unused-debug-types Common Report Var(flag_eliminate_unused_debug_types) Init(1) Perform unused type elimination in debug info femit-class-debug-always Common Report Var(flag_emit_class_debug_always) Init(1) Do not suppress C++ class debug information. fexceptions Common Report Var(flag_exceptions) Enable exception handling fexpensive-optimizations Common Report Var(flag_expensive_optimizations) Perform a number of minor, expensive optimizations ffast-math Common ffinite-math-only Common Report Var(flag_finite_math_only) Assume no NaNs or infinities are generated ffixed- Common Joined RejectNegative -ffixed- Mark as being unavailable to the compiler ffloat-store Common Report Var(flag_float_store) Don't allocate floats and doubles in extended-precision registers ; Nonzero for -fforce-addr: load memory address into a register before ; reference to memory. This makes better cse but slower compilation. fforce-addr Common Report Var(flag_force_addr) Copy memory address constants into registers before use ; Nonzero for -fforce-mem: load memory value into a register ; before arithmetic on it. This makes better cse but slower compilation. fforce-mem Common Report Var(flag_force_mem) Copy memory operands into registers before use ; Nonzero means don't put addresses of constant functions in registers. ; Used for compiling the Unix kernel, where strange substitutions are ; done on the assembly output. ffunction-cse Common Report Var(flag_no_function_cse,0) Allow function addresses to be held in registers ffunction-sections Common Report Var(flag_function_sections) Place each function into its own section fgcse Common Report Var(flag_gcse) Perform global common subexpression elimination fgcse-lm Common Report Var(flag_gcse_lm) Init(1) Perform enhanced load motion during global common subexpression elimination fgcse-sm Common Report Var(flag_gcse_sm) Init(0) Perform store motion after global common subexpression elimination fgcse-las Common Report Var(flag_gcse_las) Init(0) Perform redundant load after store elimination in global common subexpression elimination fgcse-after-reload Common Report Var(flag_gcse_after_reload) Perform global common subexpression elimination after register allocation has finished fguess-branch-probability Common Report Var(flag_guess_branch_prob) Enable guessing of branch probabilities ; Nonzero means ignore `#ident' directives. 0 means handle them. ; Generate position-independent code for executables if possible ; On SVR4 targets, it also controls whether or not to emit a ; string identifying the compiler. fident Common Report Var(flag_no_ident,0) Process #ident directives fif-conversion Common Report Var(flag_if_conversion) Perform conversion of conditional jumps to branchless equivalents fif-conversion2 Common Report Var(flag_if_conversion2) Perform conversion of conditional jumps to conditional execution ; -finhibit-size-directive inhibits output of .size for ELF. ; This is used only for compiling crtstuff.c, ; and it may be extended to other effects ; needed for crtstuff.c on other systems. finhibit-size-directive Common Report Var(flag_inhibit_size_directive) Do not generate .size directives ; Nonzero means that functions declared `inline' will be treated ; as `static'. Prevents generation of zillions of copies of unused ; static inline functions; instead, `inlines' are written out ; only when actually used. Used in conjunction with -g. Also ; does the right thing with #pragma interface. finline Common Report Var(flag_no_inline,0) Init(2) Pay attention to the \"inline\" keyword finline-functions Common Report Var(flag_inline_functions) Integrate simple functions into their callers finline-functions-called-once Common Report Var(flag_inline_functions_called_once) Init(1) Integrate functions called once into their callers finline-limit- Common RejectNegative Joined UInteger finline-limit= Common RejectNegative Joined UInteger -finline-limit= Limit the size of inlined functions to finstrument-functions Common Report Var(flag_instrument_function_entry_exit) Instrument function entry and exit with profiling calls finstrument-functions-exclude-function-list= Common RejectNegative Joined -finstrument-functions-exclude-function-list=name,... Do not instrument listed functions finstrument-functions-exclude-file-list= Common RejectNegative Joined -finstrument-functions-exclude-file-list=filename,... Do not instrument functions listed in files fipa-cp Common Report Var(flag_ipa_cp) Perform Interprocedural constant propagation fipa-pure-const Common Report Var(flag_ipa_pure_const) Init(0) Discover pure and const functions fipa-pta Common Report Var(flag_ipa_pta) Init(0) Perform interprocedural points-to analysis fipa-reference Common Report Var(flag_ipa_reference) Init(0) Discover readonly and non addressable static variables fipa-type-escape Common Report Var(flag_ipa_type_escape) Init(0) Type based escape and alias analysis fivopts Common Report Var(flag_ivopts) Init(1) Optimize induction variables on trees fjump-tables Common Var(flag_jump_tables) Init(1) Use jump tables for sufficiently large switch statements fkeep-inline-functions Common Report Var(flag_keep_inline_functions) Generate code for functions even if they are fully inlined fkeep-static-consts Common Report Var(flag_keep_static_consts) Init(1) Emit static const variables even if they are not used fleading-underscore Common Report Var(flag_leading_underscore) Init(-1) Give external symbols a leading underscore floop-optimize Common Does nothing. Preserved for backward compatibility. fmath-errno Common Report Var(flag_errno_math) Init(0) Set errno after built-in math functions fmem-report Common Report Var(mem_report) Report on permanent memory allocation ; This will attempt to merge constant section constants, if 1 only ; string constants and constants from constant pool, if 2 also constant ; variables. fmerge-all-constants Common Report Var(flag_merge_constants,2) Init(1) Attempt to merge identical constants and constant variables fmerge-constants Common Report Var(flag_merge_constants,1) VarExists Attempt to merge identical constants across compilation units fmessage-length= Common RejectNegative Joined UInteger -fmessage-length= Limit diagnostics to characters per line. 0 suppresses line-wrapping fmodulo-sched Common Report Var(flag_modulo_sched) Perform SMS based modulo scheduling before the first scheduling pass fmove-loop-invariants Common Report Var(flag_move_loop_invariants) Init(1) Move loop invariant computations out of loops fmudflap Common RejectNegative Report Var(flag_mudflap) Add mudflap bounds-checking instrumentation for single-threaded program fmudflapth Common RejectNegative Report VarExists Var(flag_mudflap,2) Add mudflap bounds-checking instrumentation for multi-threaded program fmudflapir Common RejectNegative Report Var(flag_mudflap_ignore_reads) Ignore read operations when inserting mudflap instrumentation freschedule-modulo-scheduled-loops Common Report Var(flag_resched_modulo_sched) Enable/Disable the traditional scheduling in loops that already passed modulo scheduling fnon-call-exceptions Common Report Var(flag_non_call_exceptions) Support synchronous non-call exceptions fomit-frame-pointer Common Report Var(flag_omit_frame_pointer) When possible do not generate stack frames foptimize-register-move Common Report Var(flag_regmove) Do the full register move optimization pass foptimize-sibling-calls Common Report Var(flag_optimize_sibling_calls) Optimize sibling and tail recursive calls fpack-struct Common Report Var(flag_pack_struct) Pack structure members together without holes fpack-struct= Common RejectNegative Joined UInteger -fpack-struct= Set initial maximum structure member alignment fpcc-struct-return Common Report Var(flag_pcc_struct_return,1) VarExists Return small aggregates in memory, not registers fpeel-loops Common Report Var(flag_peel_loops) Perform loop peeling fpeephole Common Report Var(flag_no_peephole,0) Enable machine specific peephole optimizations fpeephole2 Common Report Var(flag_peephole2) Enable an RTL peephole pass before sched2 fPIC Common Report Var(flag_pic,2) Generate position-independent code if possible (large mode) fPIE Common Report Var(flag_pie,2) Generate position-independent code for executables if possible (large mode) fpic Common Report Var(flag_pic,1) VarExists Generate position-independent code if possible (small mode) fpie Common Report Var(flag_pie,1) VarExists Generate position-independent code for executables if possible (small mode) fprefetch-loop-arrays Common Report Var(flag_prefetch_loop_arrays) Generate prefetch instructions, if available, for arrays in loops fprofile Common Report Var(profile_flag) Enable basic program profiling code fprofile-arcs Common Report Var(profile_arc_flag) Insert arc-based program profiling code fprofile-generate Common Enable common options for generating profile info for profile feedback directed optimizations fprofile-use Common Enable common options for performing profile feedback directed optimizations fprofile-values Common Report Var(flag_profile_values) Insert code to profile values of expressions frandom-seed Common frandom-seed= Common Joined RejectNegative -frandom-seed= Make compile reproducible using freg-struct-return Common Report Var(flag_pcc_struct_return,0) VarExists Return small aggregates in registers fregmove Common Report Var(flag_regmove) Enables a register move optimization frename-registers Common Report Var(flag_rename_registers) Init(2) Perform a register renaming optimization pass freorder-blocks Common Report Var(flag_reorder_blocks) Reorder basic blocks to improve code placement freorder-blocks-and-partition Common Report Var(flag_reorder_blocks_and_partition) Reorder basic blocks and partition into hot and cold sections freorder-functions Common Report Var(flag_reorder_functions) Reorder functions to improve code placement frerun-cse-after-loop Common Report Var(flag_rerun_cse_after_loop) Init(2) Add a common subexpression elimination pass after loop optimizations frerun-loop-opt Common Does nothing. Preserved for backward compatibility. frounding-math Common Report Var(flag_rounding_math) Disable optimizations that assume default FP rounding behavior fsched-interblock Common Report Var(flag_schedule_interblock) Init(1) Enable scheduling across basic blocks fsched-spec Common Report Var(flag_schedule_speculative) Init(1) Allow speculative motion of non-loads fsched-spec-load Common Report Var(flag_schedule_speculative_load) Allow speculative motion of some loads fsched-spec-load-dangerous Common Report Var(flag_schedule_speculative_load_dangerous) Allow speculative motion of more loads fsched-verbose= Common RejectNegative Joined -fsched-verbose= Set the verbosity level of the scheduler fsched2-use-superblocks Common Report Var(flag_sched2_use_superblocks) If scheduling post reload, do superblock scheduling fsched2-use-traces Common Report Var(flag_sched2_use_traces) If scheduling post reload, do trace scheduling fschedule-insns Common Report Var(flag_schedule_insns) Reschedule instructions before register allocation fschedule-insns2 Common Report Var(flag_schedule_insns_after_reload) Reschedule instructions after register allocation ; sched_stalled_insns means that insns can be moved prematurely from the queue ; of stalled insns into the ready list. fsched-stalled-insns Common Report Var(flag_sched_stalled_insns) Allow premature scheduling of queued insns fsched-stalled-insns= Common RejectNegative Joined UInteger -fsched-stalled-insns= Set number of queued insns that can be prematurely scheduled ; sched_stalled_insns_dep controls how many recently scheduled cycles will ; be examined for a dependency on a stalled insn that is candidate for ; premature removal from the queue of stalled insns into the ready list (has ; an effect only if the flag 'sched_stalled_insns' is set). fsched-stalled-insns-dep Common Report Var(flag_sched_stalled_insns_dep,1) Init(1) Set dependence distance checking in premature scheduling of queued insns fsched-stalled-insns-dep= Common RejectNegative Joined UInteger -fsched-stalled-insns-dep= Set dependence distance checking in premature scheduling of queued insns fsection-anchors Common Report Var(flag_section_anchors) Access data in the same section from shared anchor points frtl-abstract-sequences Common Report Var(flag_rtl_seqabstr) Perform sequence abstraction optimization on RTL fsee Common Report Var(flag_see) Init(0) Eliminate redundant sign extensions using LCM. fshow-column Common C ObjC C++ ObjC++ Report Var(flag_show_column) Init(1) Show column numbers in diagnostics, when available. Default on fsignaling-nans Common Report Var(flag_signaling_nans) Disable optimizations observable by IEEE signaling NaNs fsingle-precision-constant Common Report Var(flag_single_precision_constant) Convert floating point constants to single precision constants fsplit-ivs-in-unroller Common Report Var(flag_split_ivs_in_unroller) Init(1) Split lifetimes of induction variables when loops are unrolled fvariable-expansion-in-unroller Common Report Var(flag_variable_expansion_in_unroller) Apply variable expansion when loops are unrolled ; Emit code to probe the stack, to help detect stack overflow; also ; may cause large objects to be allocated dynamically. fstack-check Common Report Var(flag_stack_check) Insert stack checking code into the program fstack-limit Common fstack-limit-register= Common RejectNegative Joined -fstack-limit-register= Trap if the stack goes past fstack-limit-symbol= Common RejectNegative Joined -fstack-limit-symbol= Trap if the stack goes past symbol fstack-protector Common Report Var(flag_stack_protect, 1) Use propolice as a stack protection method fstack-protector-all Common Report RejectNegative Var(flag_stack_protect, 2) VarExists Use a stack protection method for every function +fstack-protector-strong +Common Report RejectNegative Var(flag_stack_protect, 3) +Use a smart stack protection method for certain functions + fstrength-reduce Common Does nothing. Preserved for backward compatibility. ; Nonzero if we should do (language-dependent) alias analysis. ; Typically, this analysis will assume that expressions of certain ; types do not alias expressions of certain other types. Only used ; if alias analysis (in general) is enabled. fstrict-aliasing Common Report Var(flag_strict_aliasing) Assume strict aliasing rules apply fstrict-overflow Common Report Var(flag_strict_overflow) Treat signed overflow as undefined fsyntax-only Common Report Var(flag_syntax_only) Check for syntax errors, then stop ftest-coverage Common Report Var(flag_test_coverage) Create data files needed by \"gcov\" fthread-jumps Common Report Var(flag_thread_jumps) Perform jump threading optimizations ftime-report Common Report Var(time_report) Report the time taken by each compiler pass ftls-model= Common Joined RejectNegative -ftls-model=[global-dynamic|local-dynamic|initial-exec|local-exec] Set the default thread-local storage code generation model ftoplevel-reorder Common Report Var(flag_toplevel_reorder) Init(1) Reorder top level functions, variables, and asms ftracer Common Report Var(flag_tracer) Perform superblock formation via tail duplication ; Zero means that floating-point math operations cannot generate a ; (user-visible) trap. This is the case, for example, in nonstop ; IEEE 754 arithmetic. ftrapping-math Common Report Var(flag_trapping_math) Init(1) Assume floating-point operations can trap ftrapv Common Report Var(flag_trapv) Trap for signed overflow in addition, subtraction and multiplication ftree-ccp Common Report Var(flag_tree_ccp) Enable SSA-CCP optimization on trees ftree-store-ccp Common Report Var(flag_tree_store_ccp) Enable SSA-CCP optimization for stores and loads ftree-ch Common Report Var(flag_tree_ch) Enable loop header copying on trees ftree-combine-temps Common Report Var(flag_tree_combine_temps) Coalesce memory temporaries in the SSA->normal pass ftree-copyrename Common Report Var(flag_tree_copyrename) Replace SSA temporaries with better names in copies ftree-copy-prop Common Report Var(flag_tree_copy_prop) Enable copy propagation on trees ftree-store-copy-prop Common Report Var(flag_tree_store_copy_prop) Enable copy propagation for stores and loads ftree-dce Common Report Var(flag_tree_dce) Enable SSA dead code elimination optimization on trees ftree-dominator-opts Common Report Var(flag_tree_dom) Enable dominator optimizations ftree-dse Common Report Var(flag_tree_dse) Enable dead store elimination ftree-fre Common Report Var(flag_tree_fre) Enable Full Redundancy Elimination (FRE) on trees ftree-loop-im Common Report Var(flag_tree_loop_im) Init(1) Enable loop invariant motion on trees ftree-loop-linear Common Report Var(flag_tree_loop_linear) Enable linear loop transforms on trees ftree-loop-ivcanon Common Report Var(flag_tree_loop_ivcanon) Init(1) Create canonical induction variables in loops ftree-loop-optimize Common Report Var(flag_tree_loop_optimize) Init(1) Enable loop optimizations on tree level ftree-pre Common Report Var(flag_tree_pre) Enable SSA-PRE optimization on trees ftree-salias Common Report Var(flag_tree_salias) Perform structural alias analysis ftree-sink Common Report Var(flag_tree_sink) Enable SSA code sinking on trees ftree-sra Common Report Var(flag_tree_sra) Perform scalar replacement of aggregates ftree-ter Common Report Var(flag_tree_ter) Replace temporary expressions in the SSA->normal pass ftree-lrs Common Report Var(flag_tree_live_range_split) Perform live range splitting during the SSA->normal pass ftree-vrp Common Report Var(flag_tree_vrp) Init(0) Perform Value Range Propagation on trees funit-at-a-time Common Report Var(flag_unit_at_a_time) Compile whole compilation unit at a time funroll-loops Common Report Var(flag_unroll_loops) Perform loop unrolling when iteration count is known funroll-all-loops Common Report Var(flag_unroll_all_loops) Perform loop unrolling for all loops ; Nonzero means that loop optimizer may assume that the induction variables ; that control loops do not overflow and that the loops with nontrivial ; exit condition are not infinite funsafe-loop-optimizations Common Report Var(flag_unsafe_loop_optimizations) Allow loop optimizations to assume that the loops behave in normal way ; Nonzero means that unsafe floating-point math optimizations are allowed ; for the sake of speed. IEEE compliance is not guaranteed, and operations ; are allowed to assume that their arguments and results are "normal" ; (e.g., nonnegative for SQRT). funsafe-math-optimizations Common Report Var(flag_unsafe_math_optimizations) Allow math optimizations that may violate IEEE or ISO standards funswitch-loops Common Report Var(flag_unswitch_loops) Perform loop unswitching funwind-tables Common Report Var(flag_unwind_tables) Just generate unwind tables for exception handling fvar-tracking Common Report Var(flag_var_tracking) VarExists Perform variable tracking ftree-vectorize Common Report Var(flag_tree_vectorize) Enable loop vectorization on trees ftree-vect-loop-version Common Report Var(flag_tree_vect_loop_version) Init(1) Enable loop versioning when doing loop vectorization on trees ftree-vectorizer-verbose= Common RejectNegative Joined -ftree-vectorizer-verbose= Set the verbosity level of the vectorizer ; -fverbose-asm causes extra commentary information to be produced in ; the generated assembly code (to make it more readable). This option ; is generally only of use to those who actually need to read the ; generated assembly code (perhaps while debugging the compiler itself). ; -fno-verbose-asm, the default, causes the extra information ; to not be added and is useful when comparing two assembler files. fverbose-asm Common Report Var(flag_verbose_asm) Add extra commentary to assembler output fvisibility= Common Joined RejectNegative -fvisibility=[default|internal|hidden|protected] Set the default symbol visibility fvpt Common Report Var(flag_value_profile_transformations) Use expression value profiles in optimizations fweb Common Report Var(flag_web) Init(2) Construct webs and split unrelated uses of single variable fwhole-program Common Report Var(flag_whole_program) Init(0) Perform whole program optimizations fwrapv Common Report Var(flag_wrapv) Assume signed arithmetic overflow wraps around fzero-initialized-in-bss Common Report Var(flag_zero_initialized_in_bss) Init(1) Put zero initialized data in the bss section g Common JoinedOrMissing Generate debug information in default format gcoff Common JoinedOrMissing Negative(gdwarf-2) Generate debug information in COFF format gdwarf-2 Common JoinedOrMissing Negative(gstabs) Generate debug information in DWARF v2 format ggdb Common JoinedOrMissing Generate debug information in default extended format gstabs Common JoinedOrMissing Negative(gstabs+) Generate debug information in STABS format gstabs+ Common JoinedOrMissing Negative(gvms) Generate debug information in extended STABS format gvms Common JoinedOrMissing Negative(gxcoff) Generate debug information in VMS format gxcoff Common JoinedOrMissing Negative(gxcoff+) Generate debug information in XCOFF format gxcoff+ Common JoinedOrMissing Negative(gcoff) Generate debug information in extended XCOFF format o Common Joined Separate -o Place output into p Common Var(profile_flag) Enable function profiling pedantic Common Var(pedantic) Issue warnings needed for strict compliance to the standard pedantic-errors Common Like -pedantic but issue them as errors quiet Common Var(quiet_flag) Do not display functions compiled or elapsed time version Common Var(version_flag) Display the compiler's version w Common Var(inhibit_warnings) Suppress warnings ; This comment is to ensure we retain the blank line above. Index: stable/10/contrib/gcc/doc/cpp.texi =================================================================== --- stable/10/contrib/gcc/doc/cpp.texi (revision 286712) +++ stable/10/contrib/gcc/doc/cpp.texi (revision 286713) @@ -1,4251 +1,4255 @@ \input texinfo @setfilename cpp.info @settitle The C Preprocessor @setchapternewpage off @c @smallbook @c @cropmarks @c @finalout @include gcc-common.texi @copying @c man begin COPYRIGHT Copyright @copyright{} 1987, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation. A copy of the license is included in the @c man end section entitled ``GNU Free Documentation License''. @ignore @c man begin COPYRIGHT man page gfdl(7). @c man end @end ignore @c man begin COPYRIGHT This manual contains no Invariant Sections. The Front-Cover Texts are (a) (see below), and the Back-Cover Texts are (b) (see below). (a) The FSF's Front-Cover Text is: A GNU Manual (b) The FSF's Back-Cover Text is: You have freedom to copy and modify this GNU Manual, like GNU software. Copies published by the Free Software Foundation raise funds for GNU development. @c man end @end copying @c Create a separate index for command line options. @defcodeindex op @syncodeindex vr op @c Used in cppopts.texi and cppenv.texi. @set cppmanual @ifinfo @dircategory Software development @direntry * Cpp: (cpp). The GNU C preprocessor. @end direntry @end ifinfo @titlepage @title The C Preprocessor @versionsubtitle @author Richard M. Stallman, Zachary Weinberg @page @c There is a fill at the bottom of the page, so we need a filll to @c override it. @vskip 0pt plus 1filll @insertcopying @end titlepage @contents @page @ifnottex @node Top @top The C preprocessor implements the macro language used to transform C and C++ programs before they are compiled. It can also be useful on its own. @menu * Overview:: * Header Files:: * Macros:: * Conditionals:: * Diagnostics:: * Line Control:: * Pragmas:: * Other Directives:: * Preprocessor Output:: * Traditional Mode:: * Implementation Details:: * Invocation:: * Environment Variables:: * GNU Free Documentation License:: * Index of Directives:: * Option Index:: * Concept Index:: @detailmenu --- The Detailed Node Listing --- Overview * Character sets:: * Initial processing:: * Tokenization:: * The preprocessing language:: Header Files * Include Syntax:: * Include Operation:: * Search Path:: * Once-Only Headers:: * Computed Includes:: * Wrapper Headers:: * System Headers:: Macros * Object-like Macros:: * Function-like Macros:: * Macro Arguments:: * Stringification:: * Concatenation:: * Variadic Macros:: * Predefined Macros:: * Undefining and Redefining Macros:: * Directives Within Macro Arguments:: * Macro Pitfalls:: Predefined Macros * Standard Predefined Macros:: * Common Predefined Macros:: * System-specific Predefined Macros:: * C++ Named Operators:: Macro Pitfalls * Misnesting:: * Operator Precedence Problems:: * Swallowing the Semicolon:: * Duplication of Side Effects:: * Self-Referential Macros:: * Argument Prescan:: * Newlines in Arguments:: Conditionals * Conditional Uses:: * Conditional Syntax:: * Deleted Code:: Conditional Syntax * Ifdef:: * If:: * Defined:: * Else:: * Elif:: Implementation Details * Implementation-defined behavior:: * Implementation limits:: * Obsolete Features:: * Differences from previous versions:: Obsolete Features * Assertions:: * Obsolete once-only headers:: @end detailmenu @end menu @insertcopying @end ifnottex @node Overview @chapter Overview @c man begin DESCRIPTION The C preprocessor, often known as @dfn{cpp}, is a @dfn{macro processor} that is used automatically by the C compiler to transform your program before compilation. It is called a macro processor because it allows you to define @dfn{macros}, which are brief abbreviations for longer constructs. The C preprocessor is intended to be used only with C and C++ source code. In the past, it has been abused as a general text processor. It will choke on input which does not obey C's lexical rules. For example, apostrophes will be interpreted as the beginning of character constants, and cause errors. Also, you cannot rely on it preserving characteristics of the input which are not significant to C-family languages. If a Makefile is preprocessed, all the hard tabs will be removed, and the Makefile will not work. Having said that, you can often get away with using cpp on things which are not C@. Other Algol-ish programming languages are often safe (Pascal, Ada, etc.) So is assembly, with caution. @option{-traditional-cpp} mode preserves more white space, and is otherwise more permissive. Many of the problems can be avoided by writing C or C++ style comments instead of native language comments, and keeping macros simple. Wherever possible, you should use a preprocessor geared to the language you are writing in. Modern versions of the GNU assembler have macro facilities. Most high level programming languages have their own conditional compilation and inclusion mechanism. If all else fails, try a true general text processor, such as GNU M4. C preprocessors vary in some details. This manual discusses the GNU C preprocessor, which provides a small superset of the features of ISO Standard C@. In its default mode, the GNU C preprocessor does not do a few things required by the standard. These are features which are rarely, if ever, used, and may cause surprising changes to the meaning of a program which does not expect them. To get strict ISO Standard C, you should use the @option{-std=c89} or @option{-std=c99} options, depending on which version of the standard you want. To get all the mandatory diagnostics, you must also use @option{-pedantic}. @xref{Invocation}. This manual describes the behavior of the ISO preprocessor. To minimize gratuitous differences, where the ISO preprocessor's behavior does not conflict with traditional semantics, the traditional preprocessor should behave the same way. The various differences that do exist are detailed in the section @ref{Traditional Mode}. For clarity, unless noted otherwise, references to @samp{CPP} in this manual refer to GNU CPP@. @c man end @menu * Character sets:: * Initial processing:: * Tokenization:: * The preprocessing language:: @end menu @node Character sets @section Character sets Source code character set processing in C and related languages is rather complicated. The C standard discusses two character sets, but there are really at least four. The files input to CPP might be in any character set at all. CPP's very first action, before it even looks for line boundaries, is to convert the file into the character set it uses for internal processing. That set is what the C standard calls the @dfn{source} character set. It must be isomorphic with ISO 10646, also known as Unicode. CPP uses the UTF-8 encoding of Unicode. The character sets of the input files are specified using the @option{-finput-charset=} option. All preprocessing work (the subject of the rest of this manual) is carried out in the source character set. If you request textual output from the preprocessor with the @option{-E} option, it will be in UTF-8. After preprocessing is complete, string and character constants are converted again, into the @dfn{execution} character set. This character set is under control of the user; the default is UTF-8, matching the source character set. Wide string and character constants have their own character set, which is not called out specifically in the standard. Again, it is under control of the user. The default is UTF-16 or UTF-32, whichever fits in the target's @code{wchar_t} type, in the target machine's byte order.@footnote{UTF-16 does not meet the requirements of the C standard for a wide character set, but the choice of 16-bit @code{wchar_t} is enshrined in some system ABIs so we cannot fix this.} Octal and hexadecimal escape sequences do not undergo conversion; @t{'\x12'} has the value 0x12 regardless of the currently selected execution character set. All other escapes are replaced by the character in the source character set that they represent, then converted to the execution character set, just like unescaped characters. Unless the experimental @option{-fextended-identifiers} option is used, GCC does not permit the use of characters outside the ASCII range, nor @samp{\u} and @samp{\U} escapes, in identifiers. Even with that option, characters outside the ASCII range can only be specified with the @samp{\u} and @samp{\U} escapes, not used directly in identifiers. @node Initial processing @section Initial processing The preprocessor performs a series of textual transformations on its input. These happen before all other processing. Conceptually, they happen in a rigid order, and the entire file is run through each transformation before the next one begins. CPP actually does them all at once, for performance reasons. These transformations correspond roughly to the first three ``phases of translation'' described in the C standard. @enumerate @item @cindex line endings The input file is read into memory and broken into lines. Different systems use different conventions to indicate the end of a line. GCC accepts the ASCII control sequences @kbd{LF}, @kbd{@w{CR LF}} and @kbd{CR} as end-of-line markers. These are the canonical sequences used by Unix, DOS and VMS, and the classic Mac OS (before OSX) respectively. You may therefore safely copy source code written on any of those systems to a different one and use it without conversion. (GCC may lose track of the current line number if a file doesn't consistently use one convention, as sometimes happens when it is edited on computers with different conventions that share a network file system.) If the last line of any input file lacks an end-of-line marker, the end of the file is considered to implicitly supply one. The C standard says that this condition provokes undefined behavior, so GCC will emit a warning message. @item @cindex trigraphs @anchor{trigraphs}If trigraphs are enabled, they are replaced by their corresponding single characters. By default GCC ignores trigraphs, but if you request a strictly conforming mode with the @option{-std} option, or you specify the @option{-trigraphs} option, then it converts them. These are nine three-character sequences, all starting with @samp{??}, that are defined by ISO C to stand for single characters. They permit obsolete systems that lack some of C's punctuation to use C@. For example, @samp{??/} stands for @samp{\}, so @t{'??/n'} is a character constant for a newline. Trigraphs are not popular and many compilers implement them incorrectly. Portable code should not rely on trigraphs being either converted or ignored. With @option{-Wtrigraphs} GCC will warn you when a trigraph may change the meaning of your program if it were converted. @xref{Wtrigraphs}. In a string constant, you can prevent a sequence of question marks from being confused with a trigraph by inserting a backslash between the question marks, or by separating the string literal at the trigraph and making use of string literal concatenation. @t{"(??\?)"} is the string @samp{(???)}, not @samp{(?]}. Traditional C compilers do not recognize these idioms. The nine trigraphs and their replacements are @smallexample Trigraph: ??( ??) ??< ??> ??= ??/ ??' ??! ??- Replacement: [ ] @{ @} # \ ^ | ~ @end smallexample @item @cindex continued lines @cindex backslash-newline Continued lines are merged into one long line. A continued line is a line which ends with a backslash, @samp{\}. The backslash is removed and the following line is joined with the current one. No space is inserted, so you may split a line anywhere, even in the middle of a word. (It is generally more readable to split lines only at white space.) The trailing backslash on a continued line is commonly referred to as a @dfn{backslash-newline}. If there is white space between a backslash and the end of a line, that is still a continued line. However, as this is usually the result of an editing mistake, and many compilers will not accept it as a continued line, GCC will warn you about it. @item @cindex comments @cindex line comments @cindex block comments All comments are replaced with single spaces. There are two kinds of comments. @dfn{Block comments} begin with @samp{/*} and continue until the next @samp{*/}. Block comments do not nest: @smallexample /* @r{this is} /* @r{one comment} */ @r{text outside comment} @end smallexample @dfn{Line comments} begin with @samp{//} and continue to the end of the current line. Line comments do not nest either, but it does not matter, because they would end in the same place anyway. @smallexample // @r{this is} // @r{one comment} @r{text outside comment} @end smallexample @end enumerate It is safe to put line comments inside block comments, or vice versa. @smallexample @group /* @r{block comment} // @r{contains line comment} @r{yet more comment} */ @r{outside comment} // @r{line comment} /* @r{contains block comment} */ @end group @end smallexample But beware of commenting out one end of a block comment with a line comment. @smallexample @group // @r{l.c.} /* @r{block comment begins} @r{oops! this isn't a comment anymore} */ @end group @end smallexample Comments are not recognized within string literals. @t{@w{"/* blah */"}} is the string constant @samp{@w{/* blah */}}, not an empty string. Line comments are not in the 1989 edition of the C standard, but they are recognized by GCC as an extension. In C++ and in the 1999 edition of the C standard, they are an official part of the language. Since these transformations happen before all other processing, you can split a line mechanically with backslash-newline anywhere. You can comment out the end of a line. You can continue a line comment onto the next line with backslash-newline. You can even split @samp{/*}, @samp{*/}, and @samp{//} onto multiple lines with backslash-newline. For example: @smallexample @group /\ * */ # /* */ defi\ ne FO\ O 10\ 20 @end group @end smallexample @noindent is equivalent to @code{@w{#define FOO 1020}}. All these tricks are extremely confusing and should not be used in code intended to be readable. There is no way to prevent a backslash at the end of a line from being interpreted as a backslash-newline. This cannot affect any correct program, however. @node Tokenization @section Tokenization @cindex tokens @cindex preprocessing tokens After the textual transformations are finished, the input file is converted into a sequence of @dfn{preprocessing tokens}. These mostly correspond to the syntactic tokens used by the C compiler, but there are a few differences. White space separates tokens; it is not itself a token of any kind. Tokens do not have to be separated by white space, but it is often necessary to avoid ambiguities. When faced with a sequence of characters that has more than one possible tokenization, the preprocessor is greedy. It always makes each token, starting from the left, as big as possible before moving on to the next token. For instance, @code{a+++++b} is interpreted as @code{@w{a ++ ++ + b}}, not as @code{@w{a ++ + ++ b}}, even though the latter tokenization could be part of a valid C program and the former could not. Once the input file is broken into tokens, the token boundaries never change, except when the @samp{##} preprocessing operator is used to paste tokens together. @xref{Concatenation}. For example, @smallexample @group #define foo() bar foo()baz @expansion{} bar baz @emph{not} @expansion{} barbaz @end group @end smallexample The compiler does not re-tokenize the preprocessor's output. Each preprocessing token becomes one compiler token. @cindex identifiers Preprocessing tokens fall into five broad classes: identifiers, preprocessing numbers, string literals, punctuators, and other. An @dfn{identifier} is the same as an identifier in C: any sequence of letters, digits, or underscores, which begins with a letter or underscore. Keywords of C have no significance to the preprocessor; they are ordinary identifiers. You can define a macro whose name is a keyword, for instance. The only identifier which can be considered a preprocessing keyword is @code{defined}. @xref{Defined}. This is mostly true of other languages which use the C preprocessor. However, a few of the keywords of C++ are significant even in the preprocessor. @xref{C++ Named Operators}. In the 1999 C standard, identifiers may contain letters which are not part of the ``basic source character set'', at the implementation's discretion (such as accented Latin letters, Greek letters, or Chinese ideograms). This may be done with an extended character set, or the @samp{\u} and @samp{\U} escape sequences. The implementation of this feature in GCC is experimental; such characters are only accepted in the @samp{\u} and @samp{\U} forms and only if @option{-fextended-identifiers} is used. As an extension, GCC treats @samp{$} as a letter. This is for compatibility with some systems, such as VMS, where @samp{$} is commonly used in system-defined function and object names. @samp{$} is not a letter in strictly conforming mode, or if you specify the @option{-$} option. @xref{Invocation}. @cindex numbers @cindex preprocessing numbers A @dfn{preprocessing number} has a rather bizarre definition. The category includes all the normal integer and floating point constants one expects of C, but also a number of other things one might not initially recognize as a number. Formally, preprocessing numbers begin with an optional period, a required decimal digit, and then continue with any sequence of letters, digits, underscores, periods, and exponents. Exponents are the two-character sequences @samp{e+}, @samp{e-}, @samp{E+}, @samp{E-}, @samp{p+}, @samp{p-}, @samp{P+}, and @samp{P-}. (The exponents that begin with @samp{p} or @samp{P} are new to C99. They are used for hexadecimal floating-point constants.) The purpose of this unusual definition is to isolate the preprocessor from the full complexity of numeric constants. It does not have to distinguish between lexically valid and invalid floating-point numbers, which is complicated. The definition also permits you to split an identifier at any position and get exactly two tokens, which can then be pasted back together with the @samp{##} operator. It's possible for preprocessing numbers to cause programs to be misinterpreted. For example, @code{0xE+12} is a preprocessing number which does not translate to any valid numeric constant, therefore a syntax error. It does not mean @code{@w{0xE + 12}}, which is what you might have intended. @cindex string literals @cindex string constants @cindex character constants @cindex header file names @c the @: prevents makeinfo from turning '' into ". @dfn{String literals} are string constants, character constants, and header file names (the argument of @samp{#include}).@footnote{The C standard uses the term @dfn{string literal} to refer only to what we are calling @dfn{string constants}.} String constants and character constants are straightforward: @t{"@dots{}"} or @t{'@dots{}'}. In either case embedded quotes should be escaped with a backslash: @t{'\'@:'} is the character constant for @samp{'}. There is no limit on the length of a character constant, but the value of a character constant that contains more than one character is implementation-defined. @xref{Implementation Details}. Header file names either look like string constants, @t{"@dots{}"}, or are written with angle brackets instead, @t{<@dots{}>}. In either case, backslash is an ordinary character. There is no way to escape the closing quote or angle bracket. The preprocessor looks for the header file in different places depending on which form you use. @xref{Include Operation}. No string literal may extend past the end of a line. Older versions of GCC accepted multi-line string constants. You may use continued lines instead, or string constant concatenation. @xref{Differences from previous versions}. @cindex punctuators @cindex digraphs @cindex alternative tokens @dfn{Punctuators} are all the usual bits of punctuation which are meaningful to C and C++. All but three of the punctuation characters in ASCII are C punctuators. The exceptions are @samp{@@}, @samp{$}, and @samp{`}. In addition, all the two- and three-character operators are punctuators. There are also six @dfn{digraphs}, which the C++ standard calls @dfn{alternative tokens}, which are merely alternate ways to spell other punctuators. This is a second attempt to work around missing punctuation in obsolete systems. It has no negative side effects, unlike trigraphs, but does not cover as much ground. The digraphs and their corresponding normal punctuators are: @smallexample Digraph: <% %> <: :> %: %:%: Punctuator: @{ @} [ ] # ## @end smallexample @cindex other tokens Any other single character is considered ``other''. It is passed on to the preprocessor's output unmolested. The C compiler will almost certainly reject source code containing ``other'' tokens. In ASCII, the only other characters are @samp{@@}, @samp{$}, @samp{`}, and control characters other than NUL (all bits zero). (Note that @samp{$} is normally considered a letter.) All characters with the high bit set (numeric range 0x7F--0xFF) are also ``other'' in the present implementation. This will change when proper support for international character sets is added to GCC@. NUL is a special case because of the high probability that its appearance is accidental, and because it may be invisible to the user (many terminals do not display NUL at all). Within comments, NULs are silently ignored, just as any other character would be. In running text, NUL is considered white space. For example, these two directives have the same meaning. @smallexample #define X^@@1 #define X 1 @end smallexample @noindent (where @samp{^@@} is ASCII NUL)@. Within string or character constants, NULs are preserved. In the latter two cases the preprocessor emits a warning message. @node The preprocessing language @section The preprocessing language @cindex directives @cindex preprocessing directives @cindex directive line @cindex directive name After tokenization, the stream of tokens may simply be passed straight to the compiler's parser. However, if it contains any operations in the @dfn{preprocessing language}, it will be transformed first. This stage corresponds roughly to the standard's ``translation phase 4'' and is what most people think of as the preprocessor's job. The preprocessing language consists of @dfn{directives} to be executed and @dfn{macros} to be expanded. Its primary capabilities are: @itemize @bullet @item Inclusion of header files. These are files of declarations that can be substituted into your program. @item Macro expansion. You can define @dfn{macros}, which are abbreviations for arbitrary fragments of C code. The preprocessor will replace the macros with their definitions throughout the program. Some macros are automatically defined for you. @item Conditional compilation. You can include or exclude parts of the program according to various conditions. @item Line control. If you use a program to combine or rearrange source files into an intermediate file which is then compiled, you can use line control to inform the compiler where each source line originally came from. @item Diagnostics. You can detect problems at compile time and issue errors or warnings. @end itemize There are a few more, less useful, features. Except for expansion of predefined macros, all these operations are triggered with @dfn{preprocessing directives}. Preprocessing directives are lines in your program that start with @samp{#}. Whitespace is allowed before and after the @samp{#}. The @samp{#} is followed by an identifier, the @dfn{directive name}. It specifies the operation to perform. Directives are commonly referred to as @samp{#@var{name}} where @var{name} is the directive name. For example, @samp{#define} is the directive that defines a macro. The @samp{#} which begins a directive cannot come from a macro expansion. Also, the directive name is not macro expanded. Thus, if @code{foo} is defined as a macro expanding to @code{define}, that does not make @samp{#foo} a valid preprocessing directive. The set of valid directive names is fixed. Programs cannot define new preprocessing directives. Some directives require arguments; these make up the rest of the directive line and must be separated from the directive name by whitespace. For example, @samp{#define} must be followed by a macro name and the intended expansion of the macro. A preprocessing directive cannot cover more than one line. The line may, however, be continued with backslash-newline, or by a block comment which extends past the end of the line. In either case, when the directive is processed, the continuations have already been merged with the first line to make one long line. @node Header Files @chapter Header Files @cindex header file A header file is a file containing C declarations and macro definitions (@pxref{Macros}) to be shared between several source files. You request the use of a header file in your program by @dfn{including} it, with the C preprocessing directive @samp{#include}. Header files serve two purposes. @itemize @bullet @item @cindex system header files System header files declare the interfaces to parts of the operating system. You include them in your program to supply the definitions and declarations you need to invoke system calls and libraries. @item Your own header files contain declarations for interfaces between the source files of your program. Each time you have a group of related declarations and macro definitions all or most of which are needed in several different source files, it is a good idea to create a header file for them. @end itemize Including a header file produces the same results as copying the header file into each source file that needs it. Such copying would be time-consuming and error-prone. With a header file, the related declarations appear in only one place. If they need to be changed, they can be changed in one place, and programs that include the header file will automatically use the new version when next recompiled. The header file eliminates the labor of finding and changing all the copies as well as the risk that a failure to find one copy will result in inconsistencies within a program. In C, the usual convention is to give header files names that end with @file{.h}. It is most portable to use only letters, digits, dashes, and underscores in header file names, and at most one dot. @menu * Include Syntax:: * Include Operation:: * Search Path:: * Once-Only Headers:: * Computed Includes:: * Wrapper Headers:: * System Headers:: @end menu @node Include Syntax @section Include Syntax @findex #include Both user and system header files are included using the preprocessing directive @samp{#include}. It has two variants: @table @code @item #include <@var{file}> This variant is used for system header files. It searches for a file named @var{file} in a standard list of system directories. You can prepend directories to this list with the @option{-I} option (@pxref{Invocation}). @item #include "@var{file}" This variant is used for header files of your own program. It searches for a file named @var{file} first in the directory containing the current file, then in the quote directories and then the same directories used for @code{<@var{file}>}. You can prepend directories to the list of quote directories with the @option{-iquote} option. @end table The argument of @samp{#include}, whether delimited with quote marks or angle brackets, behaves like a string constant in that comments are not recognized, and macro names are not expanded. Thus, @code{@w{#include }} specifies inclusion of a system header file named @file{x/*y}. However, if backslashes occur within @var{file}, they are considered ordinary text characters, not escape characters. None of the character escape sequences appropriate to string constants in C are processed. Thus, @code{@w{#include "x\n\\y"}} specifies a filename containing three backslashes. (Some systems interpret @samp{\} as a pathname separator. All of these also interpret @samp{/} the same way. It is most portable to use only @samp{/}.) It is an error if there is anything (other than comments) on the line after the file name. @node Include Operation @section Include Operation The @samp{#include} directive works by directing the C preprocessor to scan the specified file as input before continuing with the rest of the current file. The output from the preprocessor contains the output already generated, followed by the output resulting from the included file, followed by the output that comes from the text after the @samp{#include} directive. For example, if you have a header file @file{header.h} as follows, @smallexample char *test (void); @end smallexample @noindent and a main program called @file{program.c} that uses the header file, like this, @smallexample int x; #include "header.h" int main (void) @{ puts (test ()); @} @end smallexample @noindent the compiler will see the same token stream as it would if @file{program.c} read @smallexample int x; char *test (void); int main (void) @{ puts (test ()); @} @end smallexample Included files are not limited to declarations and macro definitions; those are merely the typical uses. Any fragment of a C program can be included from another file. The include file could even contain the beginning of a statement that is concluded in the containing file, or the end of a statement that was started in the including file. However, an included file must consist of complete tokens. Comments and string literals which have not been closed by the end of an included file are invalid. For error recovery, they are considered to end at the end of the file. To avoid confusion, it is best if header files contain only complete syntactic units---function declarations or definitions, type declarations, etc. The line following the @samp{#include} directive is always treated as a separate line by the C preprocessor, even if the included file lacks a final newline. @node Search Path @section Search Path GCC looks in several different places for headers. On a normal Unix system, if you do not instruct it otherwise, it will look for headers requested with @code{@w{#include <@var{file}>}} in: @smallexample /usr/local/include @var{libdir}/gcc/@var{target}/@var{version}/include /usr/@var{target}/include /usr/include @end smallexample For C++ programs, it will also look in @file{/usr/include/g++-v3}, first. In the above, @var{target} is the canonical name of the system GCC was configured to compile code for; often but not always the same as the canonical name of the system it runs on. @var{version} is the version of GCC in use. You can add to this list with the @option{-I@var{dir}} command line option. All the directories named by @option{-I} are searched, in left-to-right order, @emph{before} the default directories. The only exception is when @file{dir} is already searched by default. In this case, the option is ignored and the search order for system directories remains unchanged. Duplicate directories are removed from the quote and bracket search chains before the two chains are merged to make the final search chain. Thus, it is possible for a directory to occur twice in the final search chain if it was specified in both the quote and bracket chains. You can prevent GCC from searching any of the default directories with the @option{-nostdinc} option. This is useful when you are compiling an operating system kernel or some other program that does not use the standard C library facilities, or the standard C library itself. @option{-I} options are not ignored as described above when @option{-nostdinc} is in effect. GCC looks for headers requested with @code{@w{#include "@var{file}"}} first in the directory containing the current file, then in the directories as specified by @option{-iquote} options, then in the same places it would have looked for a header requested with angle brackets. For example, if @file{/usr/include/sys/stat.h} contains @code{@w{#include "types.h"}}, GCC looks for @file{types.h} first in @file{/usr/include/sys}, then in its usual search path. @samp{#line} (@pxref{Line Control}) does not change GCC's idea of the directory containing the current file. You may put @option{-I-} at any point in your list of @option{-I} options. This has two effects. First, directories appearing before the @option{-I-} in the list are searched only for headers requested with quote marks. Directories after @option{-I-} are searched for all headers. Second, the directory containing the current file is not searched for anything, unless it happens to be one of the directories named by an @option{-I} switch. @option{-I-} is deprecated, @option{-iquote} should be used instead. @option{-I. -I-} is not the same as no @option{-I} options at all, and does not cause the same behavior for @samp{<>} includes that @samp{""} includes get with no special options. @option{-I.} searches the compiler's current working directory for header files. That may or may not be the same as the directory containing the current file. If you need to look for headers in a directory named @file{-}, write @option{-I./-}. There are several more ways to adjust the header search path. They are generally less useful. @xref{Invocation}. @node Once-Only Headers @section Once-Only Headers @cindex repeated inclusion @cindex including just once @cindex wrapper @code{#ifndef} If a header file happens to be included twice, the compiler will process its contents twice. This is very likely to cause an error, e.g.@: when the compiler sees the same structure definition twice. Even if it does not, it will certainly waste time. The standard way to prevent this is to enclose the entire real contents of the file in a conditional, like this: @smallexample @group /* File foo. */ #ifndef FILE_FOO_SEEN #define FILE_FOO_SEEN @var{the entire file} #endif /* !FILE_FOO_SEEN */ @end group @end smallexample This construct is commonly known as a @dfn{wrapper #ifndef}. When the header is included again, the conditional will be false, because @code{FILE_FOO_SEEN} is defined. The preprocessor will skip over the entire contents of the file, and the compiler will not see it twice. CPP optimizes even further. It remembers when a header file has a wrapper @samp{#ifndef}. If a subsequent @samp{#include} specifies that header, and the macro in the @samp{#ifndef} is still defined, it does not bother to rescan the file at all. You can put comments outside the wrapper. They will not interfere with this optimization. @cindex controlling macro @cindex guard macro The macro @code{FILE_FOO_SEEN} is called the @dfn{controlling macro} or @dfn{guard macro}. In a user header file, the macro name should not begin with @samp{_}. In a system header file, it should begin with @samp{__} to avoid conflicts with user programs. In any kind of header file, the macro name should contain the name of the file and some additional text, to avoid conflicts with other header files. @node Computed Includes @section Computed Includes @cindex computed includes @cindex macros in include Sometimes it is necessary to select one of several different header files to be included into your program. They might specify configuration parameters to be used on different sorts of operating systems, for instance. You could do this with a series of conditionals, @smallexample #if SYSTEM_1 # include "system_1.h" #elif SYSTEM_2 # include "system_2.h" #elif SYSTEM_3 @dots{} #endif @end smallexample That rapidly becomes tedious. Instead, the preprocessor offers the ability to use a macro for the header name. This is called a @dfn{computed include}. Instead of writing a header name as the direct argument of @samp{#include}, you simply put a macro name there instead: @smallexample #define SYSTEM_H "system_1.h" @dots{} #include SYSTEM_H @end smallexample @noindent @code{SYSTEM_H} will be expanded, and the preprocessor will look for @file{system_1.h} as if the @samp{#include} had been written that way originally. @code{SYSTEM_H} could be defined by your Makefile with a @option{-D} option. You must be careful when you define the macro. @samp{#define} saves tokens, not text. The preprocessor has no way of knowing that the macro will be used as the argument of @samp{#include}, so it generates ordinary tokens, not a header name. This is unlikely to cause problems if you use double-quote includes, which are close enough to string constants. If you use angle brackets, however, you may have trouble. The syntax of a computed include is actually a bit more general than the above. If the first non-whitespace character after @samp{#include} is not @samp{"} or @samp{<}, then the entire line is macro-expanded like running text would be. If the line expands to a single string constant, the contents of that string constant are the file to be included. CPP does not re-examine the string for embedded quotes, but neither does it process backslash escapes in the string. Therefore @smallexample #define HEADER "a\"b" #include HEADER @end smallexample @noindent looks for a file named @file{a\"b}. CPP searches for the file according to the rules for double-quoted includes. If the line expands to a token stream beginning with a @samp{<} token and including a @samp{>} token, then the tokens between the @samp{<} and the first @samp{>} are combined to form the filename to be included. Any whitespace between tokens is reduced to a single space; then any space after the initial @samp{<} is retained, but a trailing space before the closing @samp{>} is ignored. CPP searches for the file according to the rules for angle-bracket includes. In either case, if there are any tokens on the line after the file name, an error occurs and the directive is not processed. It is also an error if the result of expansion does not match either of the two expected forms. These rules are implementation-defined behavior according to the C standard. To minimize the risk of different compilers interpreting your computed includes differently, we recommend you use only a single object-like macro which expands to a string constant. This will also minimize confusion for people reading your program. @node Wrapper Headers @section Wrapper Headers @cindex wrapper headers @cindex overriding a header file @findex #include_next Sometimes it is necessary to adjust the contents of a system-provided header file without editing it directly. GCC's @command{fixincludes} operation does this, for example. One way to do that would be to create a new header file with the same name and insert it in the search path before the original header. That works fine as long as you're willing to replace the old header entirely. But what if you want to refer to the old header from the new one? You cannot simply include the old header with @samp{#include}. That will start from the beginning, and find your new header again. If your header is not protected from multiple inclusion (@pxref{Once-Only Headers}), it will recurse infinitely and cause a fatal error. You could include the old header with an absolute pathname: @smallexample #include "/usr/include/old-header.h" @end smallexample @noindent This works, but is not clean; should the system headers ever move, you would have to edit the new headers to match. There is no way to solve this problem within the C standard, but you can use the GNU extension @samp{#include_next}. It means, ``Include the @emph{next} file with this name''. This directive works like @samp{#include} except in searching for the specified file: it starts searching the list of header file directories @emph{after} the directory in which the current file was found. Suppose you specify @option{-I /usr/local/include}, and the list of directories to search also includes @file{/usr/include}; and suppose both directories contain @file{signal.h}. Ordinary @code{@w{#include }} finds the file under @file{/usr/local/include}. If that file contains @code{@w{#include_next }}, it starts searching after that directory, and finds the file in @file{/usr/include}. @samp{#include_next} does not distinguish between @code{<@var{file}>} and @code{"@var{file}"} inclusion, nor does it check that the file you specify has the same name as the current file. It simply looks for the file named, starting with the directory in the search path after the one where the current file was found. The use of @samp{#include_next} can lead to great confusion. We recommend it be used only when there is no other alternative. In particular, it should not be used in the headers belonging to a specific program; it should be used only to make global corrections along the lines of @command{fixincludes}. @node System Headers @section System Headers @cindex system header files The header files declaring interfaces to the operating system and runtime libraries often cannot be written in strictly conforming C@. Therefore, GCC gives code found in @dfn{system headers} special treatment. All warnings, other than those generated by @samp{#warning} (@pxref{Diagnostics}), are suppressed while GCC is processing a system header. Macros defined in a system header are immune to a few warnings wherever they are expanded. This immunity is granted on an ad-hoc basis, when we find that a warning generates lots of false positives because of code in macros defined in system headers. Normally, only the headers found in specific directories are considered system headers. These directories are determined when GCC is compiled. There are, however, two ways to make normal headers into system headers. The @option{-isystem} command line option adds its argument to the list of directories to search for headers, just like @option{-I}. Any headers found in that directory will be considered system headers. All directories named by @option{-isystem} are searched @emph{after} all directories named by @option{-I}, no matter what their order was on the command line. If the same directory is named by both @option{-I} and @option{-isystem}, the @option{-I} option is ignored. GCC provides an informative message when this occurs if @option{-v} is used. @findex #pragma GCC system_header There is also a directive, @code{@w{#pragma GCC system_header}}, which tells GCC to consider the rest of the current include file a system header, no matter where it was found. Code that comes before the @samp{#pragma} in the file will not be affected. @code{@w{#pragma GCC system_header}} has no effect in the primary source file. On very old systems, some of the pre-defined system header directories get even more special treatment. GNU C++ considers code in headers found in those directories to be surrounded by an @code{@w{extern "C"}} block. There is no way to request this behavior with a @samp{#pragma}, or from the command line. @node Macros @chapter Macros A @dfn{macro} is a fragment of code which has been given a name. Whenever the name is used, it is replaced by the contents of the macro. There are two kinds of macros. They differ mostly in what they look like when they are used. @dfn{Object-like} macros resemble data objects when used, @dfn{function-like} macros resemble function calls. You may define any valid identifier as a macro, even if it is a C keyword. The preprocessor does not know anything about keywords. This can be useful if you wish to hide a keyword such as @code{const} from an older compiler that does not understand it. However, the preprocessor operator @code{defined} (@pxref{Defined}) can never be defined as a macro, and C++'s named operators (@pxref{C++ Named Operators}) cannot be macros when you are compiling C++. @menu * Object-like Macros:: * Function-like Macros:: * Macro Arguments:: * Stringification:: * Concatenation:: * Variadic Macros:: * Predefined Macros:: * Undefining and Redefining Macros:: * Directives Within Macro Arguments:: * Macro Pitfalls:: @end menu @node Object-like Macros @section Object-like Macros @cindex object-like macro @cindex symbolic constants @cindex manifest constants An @dfn{object-like macro} is a simple identifier which will be replaced by a code fragment. It is called object-like because it looks like a data object in code that uses it. They are most commonly used to give symbolic names to numeric constants. @findex #define You create macros with the @samp{#define} directive. @samp{#define} is followed by the name of the macro and then the token sequence it should be an abbreviation for, which is variously referred to as the macro's @dfn{body}, @dfn{expansion} or @dfn{replacement list}. For example, @smallexample #define BUFFER_SIZE 1024 @end smallexample @noindent defines a macro named @code{BUFFER_SIZE} as an abbreviation for the token @code{1024}. If somewhere after this @samp{#define} directive there comes a C statement of the form @smallexample foo = (char *) malloc (BUFFER_SIZE); @end smallexample @noindent then the C preprocessor will recognize and @dfn{expand} the macro @code{BUFFER_SIZE}. The C compiler will see the same tokens as it would if you had written @smallexample foo = (char *) malloc (1024); @end smallexample By convention, macro names are written in uppercase. Programs are easier to read when it is possible to tell at a glance which names are macros. The macro's body ends at the end of the @samp{#define} line. You may continue the definition onto multiple lines, if necessary, using backslash-newline. When the macro is expanded, however, it will all come out on one line. For example, @smallexample #define NUMBERS 1, \ 2, \ 3 int x[] = @{ NUMBERS @}; @expansion{} int x[] = @{ 1, 2, 3 @}; @end smallexample @noindent The most common visible consequence of this is surprising line numbers in error messages. There is no restriction on what can go in a macro body provided it decomposes into valid preprocessing tokens. Parentheses need not balance, and the body need not resemble valid C code. (If it does not, you may get error messages from the C compiler when you use the macro.) The C preprocessor scans your program sequentially. Macro definitions take effect at the place you write them. Therefore, the following input to the C preprocessor @smallexample foo = X; #define X 4 bar = X; @end smallexample @noindent produces @smallexample foo = X; bar = 4; @end smallexample When the preprocessor expands a macro name, the macro's expansion replaces the macro invocation, then the expansion is examined for more macros to expand. For example, @smallexample @group #define TABLESIZE BUFSIZE #define BUFSIZE 1024 TABLESIZE @expansion{} BUFSIZE @expansion{} 1024 @end group @end smallexample @noindent @code{TABLESIZE} is expanded first to produce @code{BUFSIZE}, then that macro is expanded to produce the final result, @code{1024}. Notice that @code{BUFSIZE} was not defined when @code{TABLESIZE} was defined. The @samp{#define} for @code{TABLESIZE} uses exactly the expansion you specify---in this case, @code{BUFSIZE}---and does not check to see whether it too contains macro names. Only when you @emph{use} @code{TABLESIZE} is the result of its expansion scanned for more macro names. This makes a difference if you change the definition of @code{BUFSIZE} at some point in the source file. @code{TABLESIZE}, defined as shown, will always expand using the definition of @code{BUFSIZE} that is currently in effect: @smallexample #define BUFSIZE 1020 #define TABLESIZE BUFSIZE #undef BUFSIZE #define BUFSIZE 37 @end smallexample @noindent Now @code{TABLESIZE} expands (in two stages) to @code{37}. If the expansion of a macro contains its own name, either directly or via intermediate macros, it is not expanded again when the expansion is examined for more macros. This prevents infinite recursion. @xref{Self-Referential Macros}, for the precise details. @node Function-like Macros @section Function-like Macros @cindex function-like macros You can also define macros whose use looks like a function call. These are called @dfn{function-like macros}. To define a function-like macro, you use the same @samp{#define} directive, but you put a pair of parentheses immediately after the macro name. For example, @smallexample #define lang_init() c_init() lang_init() @expansion{} c_init() @end smallexample A function-like macro is only expanded if its name appears with a pair of parentheses after it. If you write just the name, it is left alone. This can be useful when you have a function and a macro of the same name, and you wish to use the function sometimes. @smallexample extern void foo(void); #define foo() /* @r{optimized inline version} */ @dots{} foo(); funcptr = foo; @end smallexample Here the call to @code{foo()} will use the macro, but the function pointer will get the address of the real function. If the macro were to be expanded, it would cause a syntax error. If you put spaces between the macro name and the parentheses in the macro definition, that does not define a function-like macro, it defines an object-like macro whose expansion happens to begin with a pair of parentheses. @smallexample #define lang_init () c_init() lang_init() @expansion{} () c_init()() @end smallexample The first two pairs of parentheses in this expansion come from the macro. The third is the pair that was originally after the macro invocation. Since @code{lang_init} is an object-like macro, it does not consume those parentheses. @node Macro Arguments @section Macro Arguments @cindex arguments @cindex macros with arguments @cindex arguments in macro definitions Function-like macros can take @dfn{arguments}, just like true functions. To define a macro that uses arguments, you insert @dfn{parameters} between the pair of parentheses in the macro definition that make the macro function-like. The parameters must be valid C identifiers, separated by commas and optionally whitespace. To invoke a macro that takes arguments, you write the name of the macro followed by a list of @dfn{actual arguments} in parentheses, separated by commas. The invocation of the macro need not be restricted to a single logical line---it can cross as many lines in the source file as you wish. The number of arguments you give must match the number of parameters in the macro definition. When the macro is expanded, each use of a parameter in its body is replaced by the tokens of the corresponding argument. (You need not use all of the parameters in the macro body.) As an example, here is a macro that computes the minimum of two numeric values, as it is defined in many C programs, and some uses. @smallexample #define min(X, Y) ((X) < (Y) ? (X) : (Y)) x = min(a, b); @expansion{} x = ((a) < (b) ? (a) : (b)); y = min(1, 2); @expansion{} y = ((1) < (2) ? (1) : (2)); z = min(a + 28, *p); @expansion{} z = ((a + 28) < (*p) ? (a + 28) : (*p)); @end smallexample @noindent (In this small example you can already see several of the dangers of macro arguments. @xref{Macro Pitfalls}, for detailed explanations.) Leading and trailing whitespace in each argument is dropped, and all whitespace between the tokens of an argument is reduced to a single space. Parentheses within each argument must balance; a comma within such parentheses does not end the argument. However, there is no requirement for square brackets or braces to balance, and they do not prevent a comma from separating arguments. Thus, @smallexample macro (array[x = y, x + 1]) @end smallexample @noindent passes two arguments to @code{macro}: @code{array[x = y} and @code{x + 1]}. If you want to supply @code{array[x = y, x + 1]} as an argument, you can write it as @code{array[(x = y, x + 1)]}, which is equivalent C code. All arguments to a macro are completely macro-expanded before they are substituted into the macro body. After substitution, the complete text is scanned again for macros to expand, including the arguments. This rule may seem strange, but it is carefully designed so you need not worry about whether any function call is actually a macro invocation. You can run into trouble if you try to be too clever, though. @xref{Argument Prescan}, for detailed discussion. For example, @code{min (min (a, b), c)} is first expanded to @smallexample min (((a) < (b) ? (a) : (b)), (c)) @end smallexample @noindent and then to @smallexample @group ((((a) < (b) ? (a) : (b))) < (c) ? (((a) < (b) ? (a) : (b))) : (c)) @end group @end smallexample @noindent (Line breaks shown here for clarity would not actually be generated.) @cindex empty macro arguments You can leave macro arguments empty; this is not an error to the preprocessor (but many macros will then expand to invalid code). You cannot leave out arguments entirely; if a macro takes two arguments, there must be exactly one comma at the top level of its argument list. Here are some silly examples using @code{min}: @smallexample min(, b) @expansion{} (( ) < (b) ? ( ) : (b)) min(a, ) @expansion{} ((a ) < ( ) ? (a ) : ( )) min(,) @expansion{} (( ) < ( ) ? ( ) : ( )) min((,),) @expansion{} (((,)) < ( ) ? ((,)) : ( )) min() @error{} macro "min" requires 2 arguments, but only 1 given min(,,) @error{} macro "min" passed 3 arguments, but takes just 2 @end smallexample Whitespace is not a preprocessing token, so if a macro @code{foo} takes one argument, @code{@w{foo ()}} and @code{@w{foo ( )}} both supply it an empty argument. Previous GNU preprocessor implementations and documentation were incorrect on this point, insisting that a function-like macro that takes a single argument be passed a space if an empty argument was required. Macro parameters appearing inside string literals are not replaced by their corresponding actual arguments. @smallexample #define foo(x) x, "x" foo(bar) @expansion{} bar, "x" @end smallexample @node Stringification @section Stringification @cindex stringification @cindex @samp{#} operator Sometimes you may want to convert a macro argument into a string constant. Parameters are not replaced inside string constants, but you can use the @samp{#} preprocessing operator instead. When a macro parameter is used with a leading @samp{#}, the preprocessor replaces it with the literal text of the actual argument, converted to a string constant. Unlike normal parameter replacement, the argument is not macro-expanded first. This is called @dfn{stringification}. There is no way to combine an argument with surrounding text and stringify it all together. Instead, you can write a series of adjacent string constants and stringified arguments. The preprocessor will replace the stringified arguments with string constants. The C compiler will then combine all the adjacent string constants into one long string. Here is an example of a macro definition that uses stringification: @smallexample @group #define WARN_IF(EXP) \ do @{ if (EXP) \ fprintf (stderr, "Warning: " #EXP "\n"); @} \ while (0) WARN_IF (x == 0); @expansion{} do @{ if (x == 0) fprintf (stderr, "Warning: " "x == 0" "\n"); @} while (0); @end group @end smallexample @noindent The argument for @code{EXP} is substituted once, as-is, into the @code{if} statement, and once, stringified, into the argument to @code{fprintf}. If @code{x} were a macro, it would be expanded in the @code{if} statement, but not in the string. The @code{do} and @code{while (0)} are a kludge to make it possible to write @code{WARN_IF (@var{arg});}, which the resemblance of @code{WARN_IF} to a function would make C programmers want to do; see @ref{Swallowing the Semicolon}. Stringification in C involves more than putting double-quote characters around the fragment. The preprocessor backslash-escapes the quotes surrounding embedded string constants, and all backslashes within string and character constants, in order to get a valid C string constant with the proper contents. Thus, stringifying @code{@w{p = "foo\n";}} results in @t{@w{"p = \"foo\\n\";"}}. However, backslashes that are not inside string or character constants are not duplicated: @samp{\n} by itself stringifies to @t{"\n"}. All leading and trailing whitespace in text being stringified is ignored. Any sequence of whitespace in the middle of the text is converted to a single space in the stringified result. Comments are replaced by whitespace long before stringification happens, so they never appear in stringified text. There is no way to convert a macro argument into a character constant. If you want to stringify the result of expansion of a macro argument, you have to use two levels of macros. @smallexample #define xstr(s) str(s) #define str(s) #s #define foo 4 str (foo) @expansion{} "foo" xstr (foo) @expansion{} xstr (4) @expansion{} str (4) @expansion{} "4" @end smallexample @code{s} is stringified when it is used in @code{str}, so it is not macro-expanded first. But @code{s} is an ordinary argument to @code{xstr}, so it is completely macro-expanded before @code{xstr} itself is expanded (@pxref{Argument Prescan}). Therefore, by the time @code{str} gets to its argument, it has already been macro-expanded. @node Concatenation @section Concatenation @cindex concatenation @cindex token pasting @cindex token concatenation @cindex @samp{##} operator It is often useful to merge two tokens into one while expanding macros. This is called @dfn{token pasting} or @dfn{token concatenation}. The @samp{##} preprocessing operator performs token pasting. When a macro is expanded, the two tokens on either side of each @samp{##} operator are combined into a single token, which then replaces the @samp{##} and the two original tokens in the macro expansion. Usually both will be identifiers, or one will be an identifier and the other a preprocessing number. When pasted, they make a longer identifier. This isn't the only valid case. It is also possible to concatenate two numbers (or a number and a name, such as @code{1.5} and @code{e3}) into a number. Also, multi-character operators such as @code{+=} can be formed by token pasting. However, two tokens that don't together form a valid token cannot be pasted together. For example, you cannot concatenate @code{x} with @code{+} in either order. If you try, the preprocessor issues a warning and emits the two tokens. Whether it puts white space between the tokens is undefined. It is common to find unnecessary uses of @samp{##} in complex macros. If you get this warning, it is likely that you can simply remove the @samp{##}. Both the tokens combined by @samp{##} could come from the macro body, but you could just as well write them as one token in the first place. Token pasting is most useful when one or both of the tokens comes from a macro argument. If either of the tokens next to an @samp{##} is a parameter name, it is replaced by its actual argument before @samp{##} executes. As with stringification, the actual argument is not macro-expanded first. If the argument is empty, that @samp{##} has no effect. Keep in mind that the C preprocessor converts comments to whitespace before macros are even considered. Therefore, you cannot create a comment by concatenating @samp{/} and @samp{*}. You can put as much whitespace between @samp{##} and its operands as you like, including comments, and you can put comments in arguments that will be concatenated. However, it is an error if @samp{##} appears at either end of a macro body. Consider a C program that interprets named commands. There probably needs to be a table of commands, perhaps an array of structures declared as follows: @smallexample @group struct command @{ char *name; void (*function) (void); @}; @end group @group struct command commands[] = @{ @{ "quit", quit_command @}, @{ "help", help_command @}, @dots{} @}; @end group @end smallexample It would be cleaner not to have to give each command name twice, once in the string constant and once in the function name. A macro which takes the name of a command as an argument can make this unnecessary. The string constant can be created with stringification, and the function name by concatenating the argument with @samp{_command}. Here is how it is done: @smallexample #define COMMAND(NAME) @{ #NAME, NAME ## _command @} struct command commands[] = @{ COMMAND (quit), COMMAND (help), @dots{} @}; @end smallexample @node Variadic Macros @section Variadic Macros @cindex variable number of arguments @cindex macros with variable arguments @cindex variadic macros A macro can be declared to accept a variable number of arguments much as a function can. The syntax for defining the macro is similar to that of a function. Here is an example: @smallexample #define eprintf(@dots{}) fprintf (stderr, __VA_ARGS__) @end smallexample This kind of macro is called @dfn{variadic}. When the macro is invoked, all the tokens in its argument list after the last named argument (this macro has none), including any commas, become the @dfn{variable argument}. This sequence of tokens replaces the identifier @code{@w{__VA_ARGS__}} in the macro body wherever it appears. Thus, we have this expansion: @smallexample eprintf ("%s:%d: ", input_file, lineno) @expansion{} fprintf (stderr, "%s:%d: ", input_file, lineno) @end smallexample The variable argument is completely macro-expanded before it is inserted into the macro expansion, just like an ordinary argument. You may use the @samp{#} and @samp{##} operators to stringify the variable argument or to paste its leading or trailing token with another token. (But see below for an important special case for @samp{##}.) If your macro is complicated, you may want a more descriptive name for the variable argument than @code{@w{__VA_ARGS__}}. CPP permits this, as an extension. You may write an argument name immediately before the @samp{@dots{}}; that name is used for the variable argument. The @code{eprintf} macro above could be written @smallexample #define eprintf(args@dots{}) fprintf (stderr, args) @end smallexample @noindent using this extension. You cannot use @code{@w{__VA_ARGS__}} and this extension in the same macro. You can have named arguments as well as variable arguments in a variadic macro. We could define @code{eprintf} like this, instead: @smallexample #define eprintf(format, @dots{}) fprintf (stderr, format, __VA_ARGS__) @end smallexample @noindent This formulation looks more descriptive, but unfortunately it is less flexible: you must now supply at least one argument after the format string. In standard C, you cannot omit the comma separating the named argument from the variable arguments. Furthermore, if you leave the variable argument empty, you will get a syntax error, because there will be an extra comma after the format string. @smallexample eprintf("success!\n", ); @expansion{} fprintf(stderr, "success!\n", ); @end smallexample GNU CPP has a pair of extensions which deal with this problem. First, you are allowed to leave the variable argument out entirely: @smallexample eprintf ("success!\n") @expansion{} fprintf(stderr, "success!\n", ); @end smallexample @noindent Second, the @samp{##} token paste operator has a special meaning when placed between a comma and a variable argument. If you write @smallexample #define eprintf(format, @dots{}) fprintf (stderr, format, ##__VA_ARGS__) @end smallexample @noindent and the variable argument is left out when the @code{eprintf} macro is used, then the comma before the @samp{##} will be deleted. This does @emph{not} happen if you pass an empty argument, nor does it happen if the token preceding @samp{##} is anything other than a comma. @smallexample eprintf ("success!\n") @expansion{} fprintf(stderr, "success!\n"); @end smallexample @noindent The above explanation is ambiguous about the case where the only macro parameter is a variable arguments parameter, as it is meaningless to try to distinguish whether no argument at all is an empty argument or a missing argument. In this case the C99 standard is clear that the comma must remain, however the existing GCC extension used to swallow the comma. So CPP retains the comma when conforming to a specific C standard, and drops it otherwise. C99 mandates that the only place the identifier @code{@w{__VA_ARGS__}} can appear is in the replacement list of a variadic macro. It may not be used as a macro name, macro argument name, or within a different type of macro. It may also be forbidden in open text; the standard is ambiguous. We recommend you avoid using it except for its defined purpose. Variadic macros are a new feature in C99. GNU CPP has supported them for a long time, but only with a named variable argument (@samp{args@dots{}}, not @samp{@dots{}} and @code{@w{__VA_ARGS__}}). If you are concerned with portability to previous versions of GCC, you should use only named variable arguments. On the other hand, if you are concerned with portability to other conforming implementations of C99, you should use only @code{@w{__VA_ARGS__}}. Previous versions of CPP implemented the comma-deletion extension much more generally. We have restricted it in this release to minimize the differences from C99. To get the same effect with both this and previous versions of GCC, the token preceding the special @samp{##} must be a comma, and there must be white space between that comma and whatever comes immediately before it: @smallexample #define eprintf(format, args@dots{}) fprintf (stderr, format , ##args) @end smallexample @noindent @xref{Differences from previous versions}, for the gory details. @node Predefined Macros @section Predefined Macros @cindex predefined macros Several object-like macros are predefined; you use them without supplying their definitions. They fall into three classes: standard, common, and system-specific. In C++, there is a fourth category, the named operators. They act like predefined macros, but you cannot undefine them. @menu * Standard Predefined Macros:: * Common Predefined Macros:: * System-specific Predefined Macros:: * C++ Named Operators:: @end menu @node Standard Predefined Macros @subsection Standard Predefined Macros @cindex standard predefined macros. The standard predefined macros are specified by the relevant language standards, so they are available with all compilers that implement those standards. Older compilers may not provide all of them. Their names all start with double underscores. @table @code @item __FILE__ This macro expands to the name of the current input file, in the form of a C string constant. This is the path by which the preprocessor opened the file, not the short name specified in @samp{#include} or as the input file name argument. For example, @code{"/usr/local/include/myheader.h"} is a possible expansion of this macro. @item __LINE__ This macro expands to the current input line number, in the form of a decimal integer constant. While we call it a predefined macro, it's a pretty strange macro, since its ``definition'' changes with each new line of source code. @end table @code{__FILE__} and @code{__LINE__} are useful in generating an error message to report an inconsistency detected by the program; the message can state the source line at which the inconsistency was detected. For example, @smallexample fprintf (stderr, "Internal error: " "negative string length " "%d at %s, line %d.", length, __FILE__, __LINE__); @end smallexample An @samp{#include} directive changes the expansions of @code{__FILE__} and @code{__LINE__} to correspond to the included file. At the end of that file, when processing resumes on the input file that contained the @samp{#include} directive, the expansions of @code{__FILE__} and @code{__LINE__} revert to the values they had before the @samp{#include} (but @code{__LINE__} is then incremented by one as processing moves to the line after the @samp{#include}). A @samp{#line} directive changes @code{__LINE__}, and may change @code{__FILE__} as well. @xref{Line Control}. C99 introduces @code{__func__}, and GCC has provided @code{__FUNCTION__} for a long time. Both of these are strings containing the name of the current function (there are slight semantic differences; see the GCC manual). Neither of them is a macro; the preprocessor does not know the name of the current function. They tend to be useful in conjunction with @code{__FILE__} and @code{__LINE__}, though. @table @code @item __DATE__ This macro expands to a string constant that describes the date on which the preprocessor is being run. The string constant contains eleven characters and looks like @code{@w{"Feb 12 1996"}}. If the day of the month is less than 10, it is padded with a space on the left. If GCC cannot determine the current date, it will emit a warning message (once per compilation) and @code{__DATE__} will expand to @code{@w{"??? ?? ????"}}. @item __TIME__ This macro expands to a string constant that describes the time at which the preprocessor is being run. The string constant contains eight characters and looks like @code{"23:59:01"}. If GCC cannot determine the current time, it will emit a warning message (once per compilation) and @code{__TIME__} will expand to @code{"??:??:??"}. @item __STDC__ In normal operation, this macro expands to the constant 1, to signify that this compiler conforms to ISO Standard C@. If GNU CPP is used with a compiler other than GCC, this is not necessarily true; however, the preprocessor always conforms to the standard unless the @option{-traditional-cpp} option is used. This macro is not defined if the @option{-traditional-cpp} option is used. On some hosts, the system compiler uses a different convention, where @code{__STDC__} is normally 0, but is 1 if the user specifies strict conformance to the C Standard. CPP follows the host convention when processing system header files, but when processing user files @code{__STDC__} is always 1. This has been reported to cause problems; for instance, some versions of Solaris provide X Windows headers that expect @code{__STDC__} to be either undefined or 1. @xref{Invocation}. @item __STDC_VERSION__ This macro expands to the C Standard's version number, a long integer constant of the form @code{@var{yyyy}@var{mm}L} where @var{yyyy} and @var{mm} are the year and month of the Standard version. This signifies which version of the C Standard the compiler conforms to. Like @code{__STDC__}, this is not necessarily accurate for the entire implementation, unless GNU CPP is being used with GCC@. The value @code{199409L} signifies the 1989 C standard as amended in 1994, which is the current default; the value @code{199901L} signifies the 1999 revision of the C standard. Support for the 1999 revision is not yet complete. This macro is not defined if the @option{-traditional-cpp} option is used, nor when compiling C++. @item __STDC_HOSTED__ This macro is defined, with value 1, if the compiler's target is a @dfn{hosted environment}. A hosted environment has the complete facilities of the standard C library available. @item __cplusplus This macro is defined when the C++ compiler is in use. You can use @code{__cplusplus} to test whether a header is compiled by a C compiler or a C++ compiler. This macro is similar to @code{__STDC_VERSION__}, in that it expands to a version number. A fully conforming implementation of the 1998 C++ standard will define this macro to @code{199711L}. The GNU C++ compiler is not yet fully conforming, so it uses @code{1} instead. It is hoped to complete the implementation of standard C++ in the near future. @item __ASSEMBLER__ This macro is defined with value 1 when preprocessing assembly language. @end table @node Common Predefined Macros @subsection Common Predefined Macros @cindex common predefined macros The common predefined macros are GNU C extensions. They are available with the same meanings regardless of the machine or operating system on which you are using GNU C@. Their names all start with double underscores. @table @code @item __GNUC__ @itemx __GNUC_MINOR__ @itemx __GNUC_PATCHLEVEL__ These macros are defined by all GNU compilers that use the C preprocessor: C and C++. Their values are the major version, minor version, and patch level of the compiler, as integer constants. For example, GCC 3.2.1 will define @code{__GNUC__} to 3, @code{__GNUC_MINOR__} to 2, and @code{__GNUC_PATCHLEVEL__} to 1. These macros are also defined if you invoke the preprocessor directly. @code{__GNUC_PATCHLEVEL__} is new to GCC 3.0; it is also present in the widely-used development snapshots leading up to 3.0 (which identify themselves as GCC 2.96 or 2.97, depending on which snapshot you have). If all you need to know is whether or not your program is being compiled by GCC, or a non-GCC compiler that claims to accept the GNU C dialects, you can simply test @code{__GNUC__}. If you need to write code which depends on a specific version, you must be more careful. Each time the minor version is increased, the patch level is reset to zero; each time the major version is increased (which happens rarely), the minor version and patch level are reset. If you wish to use the predefined macros directly in the conditional, you will need to write it like this: @smallexample /* @r{Test for GCC > 3.2.0} */ #if __GNUC__ > 3 || \ (__GNUC__ == 3 && (__GNUC_MINOR__ > 2 || \ (__GNUC_MINOR__ == 2 && \ __GNUC_PATCHLEVEL__ > 0)) @end smallexample @noindent Another approach is to use the predefined macros to calculate a single number, then compare that against a threshold: @smallexample #define GCC_VERSION (__GNUC__ * 10000 \ + __GNUC_MINOR__ * 100 \ + __GNUC_PATCHLEVEL__) @dots{} /* @r{Test for GCC > 3.2.0} */ #if GCC_VERSION > 30200 @end smallexample @noindent Many people find this form easier to understand. @item __GNUG__ The GNU C++ compiler defines this. Testing it is equivalent to testing @code{@w{(__GNUC__ && __cplusplus)}}. @item __STRICT_ANSI__ GCC defines this macro if and only if the @option{-ansi} switch, or a @option{-std} switch specifying strict conformance to some version of ISO C, was specified when GCC was invoked. It is defined to @samp{1}. This macro exists primarily to direct GNU libc's header files to restrict their definitions to the minimal set found in the 1989 C standard. @item __BASE_FILE__ This macro expands to the name of the main input file, in the form of a C string constant. This is the source file that was specified on the command line of the preprocessor or C compiler. @item __INCLUDE_LEVEL__ This macro expands to a decimal integer constant that represents the depth of nesting in include files. The value of this macro is incremented on every @samp{#include} directive and decremented at the end of every included file. It starts out at 0, it's value within the base file specified on the command line. @item __ELF__ This macro is defined if the target uses the ELF object format. @item __VERSION__ This macro expands to a string constant which describes the version of the compiler in use. You should not rely on its contents having any particular form, but it can be counted on to contain at least the release number. @item __OPTIMIZE__ @itemx __OPTIMIZE_SIZE__ @itemx __NO_INLINE__ These macros describe the compilation mode. @code{__OPTIMIZE__} is defined in all optimizing compilations. @code{__OPTIMIZE_SIZE__} is defined if the compiler is optimizing for size, not speed. @code{__NO_INLINE__} is defined if no functions will be inlined into their callers (when not optimizing, or when inlining has been specifically disabled by @option{-fno-inline}). These macros cause certain GNU header files to provide optimized definitions, using macros or inline functions, of system library functions. You should not use these macros in any way unless you make sure that programs will execute with the same effect whether or not they are defined. If they are defined, their value is 1. @item __GNUC_GNU_INLINE__ GCC defines this macro if functions declared @code{inline} will be handled in GCC's traditional gnu89 mode. In this mode an @code{extern inline} function will never be compiled as a standalone function, and an @code{inline} function which is neither @code{extern} nor @code{static} will always be compiled as a standalone function. @item __GNUC_STDC_INLINE__ GCC defines this macro if functions declared @code{inline} will be handled according to the ISO C99 standard. In this mode an @code{extern inline} function will always be compiled as a standalone externally visible function, and an @code{inline} function which is neither @code{extern} nor @code{static} will never be compiled as a standalone function. If this macro is defined, GCC supports the @code{gnu_inline} function attribute as a way to always get the gnu89 behaviour. Support for this and @code{__GNUC_GNU_INLINE__} was added in GCC 4.1.3. If neither macro is defined, an older version of GCC is being used: @code{inline} functions will be compiled in gnu89 mode, and the @code{gnu_inline} function attribute will not be recognized. @item __CHAR_UNSIGNED__ GCC defines this macro if and only if the data type @code{char} is unsigned on the target machine. It exists to cause the standard header file @file{limits.h} to work correctly. You should not use this macro yourself; instead, refer to the standard macros defined in @file{limits.h}. @item __WCHAR_UNSIGNED__ Like @code{__CHAR_UNSIGNED__}, this macro is defined if and only if the data type @code{wchar_t} is unsigned and the front-end is in C++ mode. @item __REGISTER_PREFIX__ This macro expands to a single token (not a string constant) which is the prefix applied to CPU register names in assembly language for this target. You can use it to write assembly that is usable in multiple environments. For example, in the @code{m68k-aout} environment it expands to nothing, but in the @code{m68k-coff} environment it expands to a single @samp{%}. @item __USER_LABEL_PREFIX__ This macro expands to a single token which is the prefix applied to user labels (symbols visible to C code) in assembly. For example, in the @code{m68k-aout} environment it expands to an @samp{_}, but in the @code{m68k-coff} environment it expands to nothing. This macro will have the correct definition even if @option{-f(no-)underscores} is in use, but it will not be correct if target-specific options that adjust this prefix are used (e.g.@: the OSF/rose @option{-mno-underscores} option). @item __SIZE_TYPE__ @itemx __PTRDIFF_TYPE__ @itemx __WCHAR_TYPE__ @itemx __WINT_TYPE__ @itemx __INTMAX_TYPE__ @itemx __UINTMAX_TYPE__ These macros are defined to the correct underlying types for the @code{size_t}, @code{ptrdiff_t}, @code{wchar_t}, @code{wint_t}, @code{intmax_t}, and @code{uintmax_t} typedefs, respectively. They exist to make the standard header files @file{stddef.h} and @file{wchar.h} work correctly. You should not use these macros directly; instead, include the appropriate headers and use the typedefs. @item __CHAR_BIT__ Defined to the number of bits used in the representation of the @code{char} data type. It exists to make the standard header given numerical limits work correctly. You should not use this macro directly; instead, include the appropriate headers. @item __SCHAR_MAX__ @itemx __WCHAR_MAX__ @itemx __SHRT_MAX__ @itemx __INT_MAX__ @itemx __LONG_MAX__ @itemx __LONG_LONG_MAX__ @itemx __INTMAX_MAX__ Defined to the maximum value of the @code{signed char}, @code{wchar_t}, @code{signed short}, @code{signed int}, @code{signed long}, @code{signed long long}, and @code{intmax_t} types respectively. They exist to make the standard header given numerical limits work correctly. You should not use these macros directly; instead, include the appropriate headers. @item __DEPRECATED This macro is defined, with value 1, when compiling a C++ source file with warnings about deprecated constructs enabled. These warnings are enabled by default, but can be disabled with @option{-Wno-deprecated}. @item __EXCEPTIONS This macro is defined, with value 1, when compiling a C++ source file with exceptions enabled. If @option{-fno-exceptions} was used when compiling the file, then this macro will not be defined. @item __USING_SJLJ_EXCEPTIONS__ This macro is defined, with value 1, if the compiler uses the old mechanism based on @code{setjmp} and @code{longjmp} for exception handling. @item __GXX_WEAK__ This macro is defined when compiling a C++ source file. It has the value 1 if the compiler will use weak symbols, COMDAT sections, or other similar techniques to collapse symbols with ``vague linkage'' that are defined in multiple translation units. If the compiler will not collapse such symbols, this macro is defined with value 0. In general, user code should not need to make use of this macro; the purpose of this macro is to ease implementation of the C++ runtime library provided with G++. @item __LP64__ @itemx _LP64 These macros are defined, with value 1, if (and only if) the compilation is for a target where @code{long int} and pointer both use 64-bits and @code{int} uses 32-bit. @item __SSP__ This macro is defined, with value 1, when @option{-fstack-protector} is in use. @item __SSP_ALL__ This macro is defined, with value 2, when @option{-fstack-protector-all} is in use. +@item __SSP_STRONG__ +This macro is defined, with value 3, when @option{-fstack-protector-strong} is +in use. + @item __TIMESTAMP__ This macro expands to a string constant that describes the date and time of the last modification of the current source file. The string constant contains abbreviated day of the week, month, day of the month, time in hh:mm:ss form, year and looks like @code{@w{"Sun Sep 16 01:03:52 1973"}}. If the day of the month is less than 10, it is padded with a space on the left. If GCC cannot determine the current date, it will emit a warning message (once per compilation) and @code{__TIMESTAMP__} will expand to @code{@w{"??? ??? ?? ??:??:?? ????"}}. @end table @node System-specific Predefined Macros @subsection System-specific Predefined Macros @cindex system-specific predefined macros @cindex predefined macros, system-specific @cindex reserved namespace The C preprocessor normally predefines several macros that indicate what type of system and machine is in use. They are obviously different on each target supported by GCC@. This manual, being for all systems and machines, cannot tell you what their names are, but you can use @command{cpp -dM} to see them all. @xref{Invocation}. All system-specific predefined macros expand to the constant 1, so you can test them with either @samp{#ifdef} or @samp{#if}. The C standard requires that all system-specific macros be part of the @dfn{reserved namespace}. All names which begin with two underscores, or an underscore and a capital letter, are reserved for the compiler and library to use as they wish. However, historically system-specific macros have had names with no special prefix; for instance, it is common to find @code{unix} defined on Unix systems. For all such macros, GCC provides a parallel macro with two underscores added at the beginning and the end. If @code{unix} is defined, @code{__unix__} will be defined too. There will never be more than two underscores; the parallel of @code{_mips} is @code{__mips__}. When the @option{-ansi} option, or any @option{-std} option that requests strict conformance, is given to the compiler, all the system-specific predefined macros outside the reserved namespace are suppressed. The parallel macros, inside the reserved namespace, remain defined. We are slowly phasing out all predefined macros which are outside the reserved namespace. You should never use them in new programs, and we encourage you to correct older code to use the parallel macros whenever you find it. We don't recommend you use the system-specific macros that are in the reserved namespace, either. It is better in the long run to check specifically for features you need, using a tool such as @command{autoconf}. @node C++ Named Operators @subsection C++ Named Operators @cindex named operators @cindex C++ named operators @cindex iso646.h In C++, there are eleven keywords which are simply alternate spellings of operators normally written with punctuation. These keywords are treated as such even in the preprocessor. They function as operators in @samp{#if}, and they cannot be defined as macros or poisoned. In C, you can request that those keywords take their C++ meaning by including @file{iso646.h}. That header defines each one as a normal object-like macro expanding to the appropriate punctuator. These are the named operators and their corresponding punctuators: @multitable {Named Operator} {Punctuator} @item Named Operator @tab Punctuator @item @code{and} @tab @code{&&} @item @code{and_eq} @tab @code{&=} @item @code{bitand} @tab @code{&} @item @code{bitor} @tab @code{|} @item @code{compl} @tab @code{~} @item @code{not} @tab @code{!} @item @code{not_eq} @tab @code{!=} @item @code{or} @tab @code{||} @item @code{or_eq} @tab @code{|=} @item @code{xor} @tab @code{^} @item @code{xor_eq} @tab @code{^=} @end multitable @node Undefining and Redefining Macros @section Undefining and Redefining Macros @cindex undefining macros @cindex redefining macros @findex #undef If a macro ceases to be useful, it may be @dfn{undefined} with the @samp{#undef} directive. @samp{#undef} takes a single argument, the name of the macro to undefine. You use the bare macro name, even if the macro is function-like. It is an error if anything appears on the line after the macro name. @samp{#undef} has no effect if the name is not a macro. @smallexample #define FOO 4 x = FOO; @expansion{} x = 4; #undef FOO x = FOO; @expansion{} x = FOO; @end smallexample Once a macro has been undefined, that identifier may be @dfn{redefined} as a macro by a subsequent @samp{#define} directive. The new definition need not have any resemblance to the old definition. However, if an identifier which is currently a macro is redefined, then the new definition must be @dfn{effectively the same} as the old one. Two macro definitions are effectively the same if: @itemize @bullet @item Both are the same type of macro (object- or function-like). @item All the tokens of the replacement list are the same. @item If there are any parameters, they are the same. @item Whitespace appears in the same places in both. It need not be exactly the same amount of whitespace, though. Remember that comments count as whitespace. @end itemize @noindent These definitions are effectively the same: @smallexample #define FOUR (2 + 2) #define FOUR (2 + 2) #define FOUR (2 /* @r{two} */ + 2) @end smallexample @noindent but these are not: @smallexample #define FOUR (2 + 2) #define FOUR ( 2+2 ) #define FOUR (2 * 2) #define FOUR(score,and,seven,years,ago) (2 + 2) @end smallexample If a macro is redefined with a definition that is not effectively the same as the old one, the preprocessor issues a warning and changes the macro to use the new definition. If the new definition is effectively the same, the redefinition is silently ignored. This allows, for instance, two different headers to define a common macro. The preprocessor will only complain if the definitions do not match. @node Directives Within Macro Arguments @section Directives Within Macro Arguments @cindex macro arguments and directives Occasionally it is convenient to use preprocessor directives within the arguments of a macro. The C and C++ standards declare that behavior in these cases is undefined. Versions of CPP prior to 3.2 would reject such constructs with an error message. This was the only syntactic difference between normal functions and function-like macros, so it seemed attractive to remove this limitation, and people would often be surprised that they could not use macros in this way. Moreover, sometimes people would use conditional compilation in the argument list to a normal library function like @samp{printf}, only to find that after a library upgrade @samp{printf} had changed to be a function-like macro, and their code would no longer compile. So from version 3.2 we changed CPP to successfully process arbitrary directives within macro arguments in exactly the same way as it would have processed the directive were the function-like macro invocation not present. If, within a macro invocation, that macro is redefined, then the new definition takes effect in time for argument pre-expansion, but the original definition is still used for argument replacement. Here is a pathological example: @smallexample #define f(x) x x f (1 #undef f #define f 2 f) @end smallexample @noindent which expands to @smallexample 1 2 1 2 @end smallexample @noindent with the semantics described above. @node Macro Pitfalls @section Macro Pitfalls @cindex problems with macros @cindex pitfalls of macros In this section we describe some special rules that apply to macros and macro expansion, and point out certain cases in which the rules have counter-intuitive consequences that you must watch out for. @menu * Misnesting:: * Operator Precedence Problems:: * Swallowing the Semicolon:: * Duplication of Side Effects:: * Self-Referential Macros:: * Argument Prescan:: * Newlines in Arguments:: @end menu @node Misnesting @subsection Misnesting When a macro is called with arguments, the arguments are substituted into the macro body and the result is checked, together with the rest of the input file, for more macro calls. It is possible to piece together a macro call coming partially from the macro body and partially from the arguments. For example, @smallexample #define twice(x) (2*(x)) #define call_with_1(x) x(1) call_with_1 (twice) @expansion{} twice(1) @expansion{} (2*(1)) @end smallexample Macro definitions do not have to have balanced parentheses. By writing an unbalanced open parenthesis in a macro body, it is possible to create a macro call that begins inside the macro body but ends outside of it. For example, @smallexample #define strange(file) fprintf (file, "%s %d", @dots{} strange(stderr) p, 35) @expansion{} fprintf (stderr, "%s %d", p, 35) @end smallexample The ability to piece together a macro call can be useful, but the use of unbalanced open parentheses in a macro body is just confusing, and should be avoided. @node Operator Precedence Problems @subsection Operator Precedence Problems @cindex parentheses in macro bodies You may have noticed that in most of the macro definition examples shown above, each occurrence of a macro argument name had parentheses around it. In addition, another pair of parentheses usually surround the entire macro definition. Here is why it is best to write macros that way. Suppose you define a macro as follows, @smallexample #define ceil_div(x, y) (x + y - 1) / y @end smallexample @noindent whose purpose is to divide, rounding up. (One use for this operation is to compute how many @code{int} objects are needed to hold a certain number of @code{char} objects.) Then suppose it is used as follows: @smallexample a = ceil_div (b & c, sizeof (int)); @expansion{} a = (b & c + sizeof (int) - 1) / sizeof (int); @end smallexample @noindent This does not do what is intended. The operator-precedence rules of C make it equivalent to this: @smallexample a = (b & (c + sizeof (int) - 1)) / sizeof (int); @end smallexample @noindent What we want is this: @smallexample a = ((b & c) + sizeof (int) - 1)) / sizeof (int); @end smallexample @noindent Defining the macro as @smallexample #define ceil_div(x, y) ((x) + (y) - 1) / (y) @end smallexample @noindent provides the desired result. Unintended grouping can result in another way. Consider @code{sizeof ceil_div(1, 2)}. That has the appearance of a C expression that would compute the size of the type of @code{ceil_div (1, 2)}, but in fact it means something very different. Here is what it expands to: @smallexample sizeof ((1) + (2) - 1) / (2) @end smallexample @noindent This would take the size of an integer and divide it by two. The precedence rules have put the division outside the @code{sizeof} when it was intended to be inside. Parentheses around the entire macro definition prevent such problems. Here, then, is the recommended way to define @code{ceil_div}: @smallexample #define ceil_div(x, y) (((x) + (y) - 1) / (y)) @end smallexample @node Swallowing the Semicolon @subsection Swallowing the Semicolon @cindex semicolons (after macro calls) Often it is desirable to define a macro that expands into a compound statement. Consider, for example, the following macro, that advances a pointer (the argument @code{p} says where to find it) across whitespace characters: @smallexample #define SKIP_SPACES(p, limit) \ @{ char *lim = (limit); \ while (p < lim) @{ \ if (*p++ != ' ') @{ \ p--; break; @}@}@} @end smallexample @noindent Here backslash-newline is used to split the macro definition, which must be a single logical line, so that it resembles the way such code would be laid out if not part of a macro definition. A call to this macro might be @code{SKIP_SPACES (p, lim)}. Strictly speaking, the call expands to a compound statement, which is a complete statement with no need for a semicolon to end it. However, since it looks like a function call, it minimizes confusion if you can use it like a function call, writing a semicolon afterward, as in @code{SKIP_SPACES (p, lim);} This can cause trouble before @code{else} statements, because the semicolon is actually a null statement. Suppose you write @smallexample if (*p != 0) SKIP_SPACES (p, lim); else @dots{} @end smallexample @noindent The presence of two statements---the compound statement and a null statement---in between the @code{if} condition and the @code{else} makes invalid C code. The definition of the macro @code{SKIP_SPACES} can be altered to solve this problem, using a @code{do @dots{} while} statement. Here is how: @smallexample #define SKIP_SPACES(p, limit) \ do @{ char *lim = (limit); \ while (p < lim) @{ \ if (*p++ != ' ') @{ \ p--; break; @}@}@} \ while (0) @end smallexample Now @code{SKIP_SPACES (p, lim);} expands into @smallexample do @{@dots{}@} while (0); @end smallexample @noindent which is one statement. The loop executes exactly once; most compilers generate no extra code for it. @node Duplication of Side Effects @subsection Duplication of Side Effects @cindex side effects (in macro arguments) @cindex unsafe macros Many C programs define a macro @code{min}, for ``minimum'', like this: @smallexample #define min(X, Y) ((X) < (Y) ? (X) : (Y)) @end smallexample When you use this macro with an argument containing a side effect, as shown here, @smallexample next = min (x + y, foo (z)); @end smallexample @noindent it expands as follows: @smallexample next = ((x + y) < (foo (z)) ? (x + y) : (foo (z))); @end smallexample @noindent where @code{x + y} has been substituted for @code{X} and @code{foo (z)} for @code{Y}. The function @code{foo} is used only once in the statement as it appears in the program, but the expression @code{foo (z)} has been substituted twice into the macro expansion. As a result, @code{foo} might be called two times when the statement is executed. If it has side effects or if it takes a long time to compute, the results might not be what you intended. We say that @code{min} is an @dfn{unsafe} macro. The best solution to this problem is to define @code{min} in a way that computes the value of @code{foo (z)} only once. The C language offers no standard way to do this, but it can be done with GNU extensions as follows: @smallexample #define min(X, Y) \ (@{ typeof (X) x_ = (X); \ typeof (Y) y_ = (Y); \ (x_ < y_) ? x_ : y_; @}) @end smallexample The @samp{(@{ @dots{} @})} notation produces a compound statement that acts as an expression. Its value is the value of its last statement. This permits us to define local variables and assign each argument to one. The local variables have underscores after their names to reduce the risk of conflict with an identifier of wider scope (it is impossible to avoid this entirely). Now each argument is evaluated exactly once. If you do not wish to use GNU C extensions, the only solution is to be careful when @emph{using} the macro @code{min}. For example, you can calculate the value of @code{foo (z)}, save it in a variable, and use that variable in @code{min}: @smallexample @group #define min(X, Y) ((X) < (Y) ? (X) : (Y)) @dots{} @{ int tem = foo (z); next = min (x + y, tem); @} @end group @end smallexample @noindent (where we assume that @code{foo} returns type @code{int}). @node Self-Referential Macros @subsection Self-Referential Macros @cindex self-reference A @dfn{self-referential} macro is one whose name appears in its definition. Recall that all macro definitions are rescanned for more macros to replace. If the self-reference were considered a use of the macro, it would produce an infinitely large expansion. To prevent this, the self-reference is not considered a macro call. It is passed into the preprocessor output unchanged. Consider an example: @smallexample #define foo (4 + foo) @end smallexample @noindent where @code{foo} is also a variable in your program. Following the ordinary rules, each reference to @code{foo} will expand into @code{(4 + foo)}; then this will be rescanned and will expand into @code{(4 + (4 + foo))}; and so on until the computer runs out of memory. The self-reference rule cuts this process short after one step, at @code{(4 + foo)}. Therefore, this macro definition has the possibly useful effect of causing the program to add 4 to the value of @code{foo} wherever @code{foo} is referred to. In most cases, it is a bad idea to take advantage of this feature. A person reading the program who sees that @code{foo} is a variable will not expect that it is a macro as well. The reader will come across the identifier @code{foo} in the program and think its value should be that of the variable @code{foo}, whereas in fact the value is four greater. One common, useful use of self-reference is to create a macro which expands to itself. If you write @smallexample #define EPERM EPERM @end smallexample @noindent then the macro @code{EPERM} expands to @code{EPERM}. Effectively, it is left alone by the preprocessor whenever it's used in running text. You can tell that it's a macro with @samp{#ifdef}. You might do this if you want to define numeric constants with an @code{enum}, but have @samp{#ifdef} be true for each constant. If a macro @code{x} expands to use a macro @code{y}, and the expansion of @code{y} refers to the macro @code{x}, that is an @dfn{indirect self-reference} of @code{x}. @code{x} is not expanded in this case either. Thus, if we have @smallexample #define x (4 + y) #define y (2 * x) @end smallexample @noindent then @code{x} and @code{y} expand as follows: @smallexample @group x @expansion{} (4 + y) @expansion{} (4 + (2 * x)) y @expansion{} (2 * x) @expansion{} (2 * (4 + y)) @end group @end smallexample @noindent Each macro is expanded when it appears in the definition of the other macro, but not when it indirectly appears in its own definition. @node Argument Prescan @subsection Argument Prescan @cindex expansion of arguments @cindex macro argument expansion @cindex prescan of macro arguments Macro arguments are completely macro-expanded before they are substituted into a macro body, unless they are stringified or pasted with other tokens. After substitution, the entire macro body, including the substituted arguments, is scanned again for macros to be expanded. The result is that the arguments are scanned @emph{twice} to expand macro calls in them. Most of the time, this has no effect. If the argument contained any macro calls, they are expanded during the first scan. The result therefore contains no macro calls, so the second scan does not change it. If the argument were substituted as given, with no prescan, the single remaining scan would find the same macro calls and produce the same results. You might expect the double scan to change the results when a self-referential macro is used in an argument of another macro (@pxref{Self-Referential Macros}): the self-referential macro would be expanded once in the first scan, and a second time in the second scan. However, this is not what happens. The self-references that do not expand in the first scan are marked so that they will not expand in the second scan either. You might wonder, ``Why mention the prescan, if it makes no difference? And why not skip it and make the preprocessor faster?'' The answer is that the prescan does make a difference in three special cases: @itemize @bullet @item Nested calls to a macro. We say that @dfn{nested} calls to a macro occur when a macro's argument contains a call to that very macro. For example, if @code{f} is a macro that expects one argument, @code{f (f (1))} is a nested pair of calls to @code{f}. The desired expansion is made by expanding @code{f (1)} and substituting that into the definition of @code{f}. The prescan causes the expected result to happen. Without the prescan, @code{f (1)} itself would be substituted as an argument, and the inner use of @code{f} would appear during the main scan as an indirect self-reference and would not be expanded. @item Macros that call other macros that stringify or concatenate. If an argument is stringified or concatenated, the prescan does not occur. If you @emph{want} to expand a macro, then stringify or concatenate its expansion, you can do that by causing one macro to call another macro that does the stringification or concatenation. For instance, if you have @smallexample #define AFTERX(x) X_ ## x #define XAFTERX(x) AFTERX(x) #define TABLESIZE 1024 #define BUFSIZE TABLESIZE @end smallexample then @code{AFTERX(BUFSIZE)} expands to @code{X_BUFSIZE}, and @code{XAFTERX(BUFSIZE)} expands to @code{X_1024}. (Not to @code{X_TABLESIZE}. Prescan always does a complete expansion.) @item Macros used in arguments, whose expansions contain unshielded commas. This can cause a macro expanded on the second scan to be called with the wrong number of arguments. Here is an example: @smallexample #define foo a,b #define bar(x) lose(x) #define lose(x) (1 + (x)) @end smallexample We would like @code{bar(foo)} to turn into @code{(1 + (foo))}, which would then turn into @code{(1 + (a,b))}. Instead, @code{bar(foo)} expands into @code{lose(a,b)}, and you get an error because @code{lose} requires a single argument. In this case, the problem is easily solved by the same parentheses that ought to be used to prevent misnesting of arithmetic operations: @smallexample #define foo (a,b) @exdent or #define bar(x) lose((x)) @end smallexample The extra pair of parentheses prevents the comma in @code{foo}'s definition from being interpreted as an argument separator. @end itemize @node Newlines in Arguments @subsection Newlines in Arguments @cindex newlines in macro arguments The invocation of a function-like macro can extend over many logical lines. However, in the present implementation, the entire expansion comes out on one line. Thus line numbers emitted by the compiler or debugger refer to the line the invocation started on, which might be different to the line containing the argument causing the problem. Here is an example illustrating this: @smallexample #define ignore_second_arg(a,b,c) a; c ignore_second_arg (foo (), ignored (), syntax error); @end smallexample @noindent The syntax error triggered by the tokens @code{syntax error} results in an error message citing line three---the line of ignore_second_arg--- even though the problematic code comes from line five. We consider this a bug, and intend to fix it in the near future. @node Conditionals @chapter Conditionals @cindex conditionals A @dfn{conditional} is a directive that instructs the preprocessor to select whether or not to include a chunk of code in the final token stream passed to the compiler. Preprocessor conditionals can test arithmetic expressions, or whether a name is defined as a macro, or both simultaneously using the special @code{defined} operator. A conditional in the C preprocessor resembles in some ways an @code{if} statement in C, but it is important to understand the difference between them. The condition in an @code{if} statement is tested during the execution of your program. Its purpose is to allow your program to behave differently from run to run, depending on the data it is operating on. The condition in a preprocessing conditional directive is tested when your program is compiled. Its purpose is to allow different code to be included in the program depending on the situation at the time of compilation. However, the distinction is becoming less clear. Modern compilers often do test @code{if} statements when a program is compiled, if their conditions are known not to vary at run time, and eliminate code which can never be executed. If you can count on your compiler to do this, you may find that your program is more readable if you use @code{if} statements with constant conditions (perhaps determined by macros). Of course, you can only use this to exclude code, not type definitions or other preprocessing directives, and you can only do it if the code remains syntactically valid when it is not to be used. GCC version 3 eliminates this kind of never-executed code even when not optimizing. Older versions did it only when optimizing. @menu * Conditional Uses:: * Conditional Syntax:: * Deleted Code:: @end menu @node Conditional Uses @section Conditional Uses There are three general reasons to use a conditional. @itemize @bullet @item A program may need to use different code depending on the machine or operating system it is to run on. In some cases the code for one operating system may be erroneous on another operating system; for example, it might refer to data types or constants that do not exist on the other system. When this happens, it is not enough to avoid executing the invalid code. Its mere presence will cause the compiler to reject the program. With a preprocessing conditional, the offending code can be effectively excised from the program when it is not valid. @item You may want to be able to compile the same source file into two different programs. One version might make frequent time-consuming consistency checks on its intermediate data, or print the values of those data for debugging, and the other not. @item A conditional whose condition is always false is one way to exclude code from the program but keep it as a sort of comment for future reference. @end itemize Simple programs that do not need system-specific logic or complex debugging hooks generally will not need to use preprocessing conditionals. @node Conditional Syntax @section Conditional Syntax @findex #if A conditional in the C preprocessor begins with a @dfn{conditional directive}: @samp{#if}, @samp{#ifdef} or @samp{#ifndef}. @menu * Ifdef:: * If:: * Defined:: * Else:: * Elif:: @end menu @node Ifdef @subsection Ifdef @findex #ifdef @findex #endif The simplest sort of conditional is @smallexample @group #ifdef @var{MACRO} @var{controlled text} #endif /* @var{MACRO} */ @end group @end smallexample @cindex conditional group This block is called a @dfn{conditional group}. @var{controlled text} will be included in the output of the preprocessor if and only if @var{MACRO} is defined. We say that the conditional @dfn{succeeds} if @var{MACRO} is defined, @dfn{fails} if it is not. The @var{controlled text} inside of a conditional can include preprocessing directives. They are executed only if the conditional succeeds. You can nest conditional groups inside other conditional groups, but they must be completely nested. In other words, @samp{#endif} always matches the nearest @samp{#ifdef} (or @samp{#ifndef}, or @samp{#if}). Also, you cannot start a conditional group in one file and end it in another. Even if a conditional fails, the @var{controlled text} inside it is still run through initial transformations and tokenization. Therefore, it must all be lexically valid C@. Normally the only way this matters is that all comments and string literals inside a failing conditional group must still be properly ended. The comment following the @samp{#endif} is not required, but it is a good practice if there is a lot of @var{controlled text}, because it helps people match the @samp{#endif} to the corresponding @samp{#ifdef}. Older programs sometimes put @var{MACRO} directly after the @samp{#endif} without enclosing it in a comment. This is invalid code according to the C standard. CPP accepts it with a warning. It never affects which @samp{#ifndef} the @samp{#endif} matches. @findex #ifndef Sometimes you wish to use some code if a macro is @emph{not} defined. You can do this by writing @samp{#ifndef} instead of @samp{#ifdef}. One common use of @samp{#ifndef} is to include code only the first time a header file is included. @xref{Once-Only Headers}. Macro definitions can vary between compilations for several reasons. Here are some samples. @itemize @bullet @item Some macros are predefined on each kind of machine (@pxref{System-specific Predefined Macros}). This allows you to provide code specially tuned for a particular machine. @item System header files define more macros, associated with the features they implement. You can test these macros with conditionals to avoid using a system feature on a machine where it is not implemented. @item Macros can be defined or undefined with the @option{-D} and @option{-U} command line options when you compile the program. You can arrange to compile the same source file into two different programs by choosing a macro name to specify which program you want, writing conditionals to test whether or how this macro is defined, and then controlling the state of the macro with command line options, perhaps set in the Makefile. @xref{Invocation}. @item Your program might have a special header file (often called @file{config.h}) that is adjusted when the program is compiled. It can define or not define macros depending on the features of the system and the desired capabilities of the program. The adjustment can be automated by a tool such as @command{autoconf}, or done by hand. @end itemize @node If @subsection If The @samp{#if} directive allows you to test the value of an arithmetic expression, rather than the mere existence of one macro. Its syntax is @smallexample @group #if @var{expression} @var{controlled text} #endif /* @var{expression} */ @end group @end smallexample @var{expression} is a C expression of integer type, subject to stringent restrictions. It may contain @itemize @bullet @item Integer constants. @item Character constants, which are interpreted as they would be in normal code. @item Arithmetic operators for addition, subtraction, multiplication, division, bitwise operations, shifts, comparisons, and logical operations (@code{&&} and @code{||}). The latter two obey the usual short-circuiting rules of standard C@. @item Macros. All macros in the expression are expanded before actual computation of the expression's value begins. @item Uses of the @code{defined} operator, which lets you check whether macros are defined in the middle of an @samp{#if}. @item Identifiers that are not macros, which are all considered to be the number zero. This allows you to write @code{@w{#if MACRO}} instead of @code{@w{#ifdef MACRO}}, if you know that MACRO, when defined, will always have a nonzero value. Function-like macros used without their function call parentheses are also treated as zero. In some contexts this shortcut is undesirable. The @option{-Wundef} option causes GCC to warn whenever it encounters an identifier which is not a macro in an @samp{#if}. @end itemize The preprocessor does not know anything about types in the language. Therefore, @code{sizeof} operators are not recognized in @samp{#if}, and neither are @code{enum} constants. They will be taken as identifiers which are not macros, and replaced by zero. In the case of @code{sizeof}, this is likely to cause the expression to be invalid. The preprocessor calculates the value of @var{expression}. It carries out all calculations in the widest integer type known to the compiler; on most machines supported by GCC this is 64 bits. This is not the same rule as the compiler uses to calculate the value of a constant expression, and may give different results in some cases. If the value comes out to be nonzero, the @samp{#if} succeeds and the @var{controlled text} is included; otherwise it is skipped. @node Defined @subsection Defined @cindex @code{defined} The special operator @code{defined} is used in @samp{#if} and @samp{#elif} expressions to test whether a certain name is defined as a macro. @code{defined @var{name}} and @code{defined (@var{name})} are both expressions whose value is 1 if @var{name} is defined as a macro at the current point in the program, and 0 otherwise. Thus, @code{@w{#if defined MACRO}} is precisely equivalent to @code{@w{#ifdef MACRO}}. @code{defined} is useful when you wish to test more than one macro for existence at once. For example, @smallexample #if defined (__vax__) || defined (__ns16000__) @end smallexample @noindent would succeed if either of the names @code{__vax__} or @code{__ns16000__} is defined as a macro. Conditionals written like this: @smallexample #if defined BUFSIZE && BUFSIZE >= 1024 @end smallexample @noindent can generally be simplified to just @code{@w{#if BUFSIZE >= 1024}}, since if @code{BUFSIZE} is not defined, it will be interpreted as having the value zero. If the @code{defined} operator appears as a result of a macro expansion, the C standard says the behavior is undefined. GNU cpp treats it as a genuine @code{defined} operator and evaluates it normally. It will warn wherever your code uses this feature if you use the command-line option @option{-pedantic}, since other compilers may handle it differently. @node Else @subsection Else @findex #else The @samp{#else} directive can be added to a conditional to provide alternative text to be used if the condition fails. This is what it looks like: @smallexample @group #if @var{expression} @var{text-if-true} #else /* Not @var{expression} */ @var{text-if-false} #endif /* Not @var{expression} */ @end group @end smallexample @noindent If @var{expression} is nonzero, the @var{text-if-true} is included and the @var{text-if-false} is skipped. If @var{expression} is zero, the opposite happens. You can use @samp{#else} with @samp{#ifdef} and @samp{#ifndef}, too. @node Elif @subsection Elif @findex #elif One common case of nested conditionals is used to check for more than two possible alternatives. For example, you might have @smallexample #if X == 1 @dots{} #else /* X != 1 */ #if X == 2 @dots{} #else /* X != 2 */ @dots{} #endif /* X != 2 */ #endif /* X != 1 */ @end smallexample Another conditional directive, @samp{#elif}, allows this to be abbreviated as follows: @smallexample #if X == 1 @dots{} #elif X == 2 @dots{} #else /* X != 2 and X != 1*/ @dots{} #endif /* X != 2 and X != 1*/ @end smallexample @samp{#elif} stands for ``else if''. Like @samp{#else}, it goes in the middle of a conditional group and subdivides it; it does not require a matching @samp{#endif} of its own. Like @samp{#if}, the @samp{#elif} directive includes an expression to be tested. The text following the @samp{#elif} is processed only if the original @samp{#if}-condition failed and the @samp{#elif} condition succeeds. More than one @samp{#elif} can go in the same conditional group. Then the text after each @samp{#elif} is processed only if the @samp{#elif} condition succeeds after the original @samp{#if} and all previous @samp{#elif} directives within it have failed. @samp{#else} is allowed after any number of @samp{#elif} directives, but @samp{#elif} may not follow @samp{#else}. @node Deleted Code @section Deleted Code @cindex commenting out code If you replace or delete a part of the program but want to keep the old code around for future reference, you often cannot simply comment it out. Block comments do not nest, so the first comment inside the old code will end the commenting-out. The probable result is a flood of syntax errors. One way to avoid this problem is to use an always-false conditional instead. For instance, put @code{#if 0} before the deleted code and @code{#endif} after it. This works even if the code being turned off contains conditionals, but they must be entire conditionals (balanced @samp{#if} and @samp{#endif}). Some people use @code{#ifdef notdef} instead. This is risky, because @code{notdef} might be accidentally defined as a macro, and then the conditional would succeed. @code{#if 0} can be counted on to fail. Do not use @code{#if 0} for comments which are not C code. Use a real comment, instead. The interior of @code{#if 0} must consist of complete tokens; in particular, single-quote characters must balance. Comments often contain unbalanced single-quote characters (known in English as apostrophes). These confuse @code{#if 0}. They don't confuse @samp{/*}. @node Diagnostics @chapter Diagnostics @cindex diagnostic @cindex reporting errors @cindex reporting warnings @findex #error The directive @samp{#error} causes the preprocessor to report a fatal error. The tokens forming the rest of the line following @samp{#error} are used as the error message. You would use @samp{#error} inside of a conditional that detects a combination of parameters which you know the program does not properly support. For example, if you know that the program will not run properly on a VAX, you might write @smallexample @group #ifdef __vax__ #error "Won't work on VAXen. See comments at get_last_object." #endif @end group @end smallexample If you have several configuration parameters that must be set up by the installation in a consistent way, you can use conditionals to detect an inconsistency and report it with @samp{#error}. For example, @smallexample #if !defined(UNALIGNED_INT_ASM_OP) && defined(DWARF2_DEBUGGING_INFO) #error "DWARF2_DEBUGGING_INFO requires UNALIGNED_INT_ASM_OP." #endif @end smallexample @findex #warning The directive @samp{#warning} is like @samp{#error}, but causes the preprocessor to issue a warning and continue preprocessing. The tokens following @samp{#warning} are used as the warning message. You might use @samp{#warning} in obsolete header files, with a message directing the user to the header file which should be used instead. Neither @samp{#error} nor @samp{#warning} macro-expands its argument. Internal whitespace sequences are each replaced with a single space. The line must consist of complete tokens. It is wisest to make the argument of these directives be a single string constant; this avoids problems with apostrophes and the like. @node Line Control @chapter Line Control @cindex line control The C preprocessor informs the C compiler of the location in your source code where each token came from. Presently, this is just the file name and line number. All the tokens resulting from macro expansion are reported as having appeared on the line of the source file where the outermost macro was used. We intend to be more accurate in the future. If you write a program which generates source code, such as the @command{bison} parser generator, you may want to adjust the preprocessor's notion of the current file name and line number by hand. Parts of the output from @command{bison} are generated from scratch, other parts come from a standard parser file. The rest are copied verbatim from @command{bison}'s input. You would like compiler error messages and symbolic debuggers to be able to refer to @code{bison}'s input file. @findex #line @command{bison} or any such program can arrange this by writing @samp{#line} directives into the output file. @samp{#line} is a directive that specifies the original line number and source file name for subsequent input in the current preprocessor input file. @samp{#line} has three variants: @table @code @item #line @var{linenum} @var{linenum} is a non-negative decimal integer constant. It specifies the line number which should be reported for the following line of input. Subsequent lines are counted from @var{linenum}. @item #line @var{linenum} @var{filename} @var{linenum} is the same as for the first form, and has the same effect. In addition, @var{filename} is a string constant. The following line and all subsequent lines are reported to come from the file it specifies, until something else happens to change that. @var{filename} is interpreted according to the normal rules for a string constant: backslash escapes are interpreted. This is different from @samp{#include}. Previous versions of CPP did not interpret escapes in @samp{#line}; we have changed it because the standard requires they be interpreted, and most other compilers do. @item #line @var{anything else} @var{anything else} is checked for macro calls, which are expanded. The result should match one of the above two forms. @end table @samp{#line} directives alter the results of the @code{__FILE__} and @code{__LINE__} predefined macros from that point on. @xref{Standard Predefined Macros}. They do not have any effect on @samp{#include}'s idea of the directory containing the current file. This is a change from GCC 2.95. Previously, a file reading @smallexample #line 1 "../src/gram.y" #include "gram.h" @end smallexample would search for @file{gram.h} in @file{../src}, then the @option{-I} chain; the directory containing the physical source file would not be searched. In GCC 3.0 and later, the @samp{#include} is not affected by the presence of a @samp{#line} referring to a different directory. We made this change because the old behavior caused problems when generated source files were transported between machines. For instance, it is common practice to ship generated parsers with a source release, so that people building the distribution do not need to have yacc or Bison installed. These files frequently have @samp{#line} directives referring to the directory tree of the system where the distribution was created. If GCC tries to search for headers in those directories, the build is likely to fail. The new behavior can cause failures too, if the generated file is not in the same directory as its source and it attempts to include a header which would be visible searching from the directory containing the source file. However, this problem is easily solved with an additional @option{-I} switch on the command line. The failures caused by the old semantics could sometimes be corrected only by editing the generated files, which is difficult and error-prone. @node Pragmas @chapter Pragmas The @samp{#pragma} directive is the method specified by the C standard for providing additional information to the compiler, beyond what is conveyed in the language itself. Three forms of this directive (commonly known as @dfn{pragmas}) are specified by the 1999 C standard. A C compiler is free to attach any meaning it likes to other pragmas. GCC has historically preferred to use extensions to the syntax of the language, such as @code{__attribute__}, for this purpose. However, GCC does define a few pragmas of its own. These mostly have effects on the entire translation unit or source file. In GCC version 3, all GNU-defined, supported pragmas have been given a @code{GCC} prefix. This is in line with the @code{STDC} prefix on all pragmas defined by C99. For backward compatibility, pragmas which were recognized by previous versions are still recognized without the @code{GCC} prefix, but that usage is deprecated. Some older pragmas are deprecated in their entirety. They are not recognized with the @code{GCC} prefix. @xref{Obsolete Features}. @cindex @code{_Pragma} C99 introduces the @code{@w{_Pragma}} operator. This feature addresses a major problem with @samp{#pragma}: being a directive, it cannot be produced as the result of macro expansion. @code{@w{_Pragma}} is an operator, much like @code{sizeof} or @code{defined}, and can be embedded in a macro. Its syntax is @code{@w{_Pragma (@var{string-literal})}}, where @var{string-literal} can be either a normal or wide-character string literal. It is destringized, by replacing all @samp{\\} with a single @samp{\} and all @samp{\"} with a @samp{"}. The result is then processed as if it had appeared as the right hand side of a @samp{#pragma} directive. For example, @smallexample _Pragma ("GCC dependency \"parse.y\"") @end smallexample @noindent has the same effect as @code{#pragma GCC dependency "parse.y"}. The same effect could be achieved using macros, for example @smallexample #define DO_PRAGMA(x) _Pragma (#x) DO_PRAGMA (GCC dependency "parse.y") @end smallexample The standard is unclear on where a @code{_Pragma} operator can appear. The preprocessor does not accept it within a preprocessing conditional directive like @samp{#if}. To be safe, you are probably best keeping it out of directives other than @samp{#define}, and putting it on a line of its own. This manual documents the pragmas which are meaningful to the preprocessor itself. Other pragmas are meaningful to the C or C++ compilers. They are documented in the GCC manual. @ftable @code @item #pragma GCC dependency @code{#pragma GCC dependency} allows you to check the relative dates of the current file and another file. If the other file is more recent than the current file, a warning is issued. This is useful if the current file is derived from the other file, and should be regenerated. The other file is searched for using the normal include search path. Optional trailing text can be used to give more information in the warning message. @smallexample #pragma GCC dependency "parse.y" #pragma GCC dependency "/usr/include/time.h" rerun fixincludes @end smallexample @item #pragma GCC poison Sometimes, there is an identifier that you want to remove completely from your program, and make sure that it never creeps back in. To enforce this, you can @dfn{poison} the identifier with this pragma. @code{#pragma GCC poison} is followed by a list of identifiers to poison. If any of those identifiers appears anywhere in the source after the directive, it is a hard error. For example, @smallexample #pragma GCC poison printf sprintf fprintf sprintf(some_string, "hello"); @end smallexample @noindent will produce an error. If a poisoned identifier appears as part of the expansion of a macro which was defined before the identifier was poisoned, it will @emph{not} cause an error. This lets you poison an identifier without worrying about system headers defining macros that use it. For example, @smallexample #define strrchr rindex #pragma GCC poison rindex strrchr(some_string, 'h'); @end smallexample @noindent will not produce an error. @item #pragma GCC system_header This pragma takes no arguments. It causes the rest of the code in the current file to be treated as if it came from a system header. @xref{System Headers}. @end ftable @node Other Directives @chapter Other Directives @findex #ident @findex #sccs The @samp{#ident} directive takes one argument, a string constant. On some systems, that string constant is copied into a special segment of the object file. On other systems, the directive is ignored. The @samp{#sccs} directive is a synonym for @samp{#ident}. These directives are not part of the C standard, but they are not official GNU extensions either. What historical information we have been able to find, suggests they originated with System V@. @cindex null directive The @dfn{null directive} consists of a @samp{#} followed by a newline, with only whitespace (including comments) in between. A null directive is understood as a preprocessing directive but has no effect on the preprocessor output. The primary significance of the existence of the null directive is that an input line consisting of just a @samp{#} will produce no output, rather than a line of output containing just a @samp{#}. Supposedly some old C programs contain such lines. @node Preprocessor Output @chapter Preprocessor Output When the C preprocessor is used with the C or C++ compilers, it is integrated into the compiler and communicates a stream of binary tokens directly to the compiler's parser. However, it can also be used in the more conventional standalone mode, where it produces textual output. @c FIXME: Document the library interface. @cindex output format The output from the C preprocessor looks much like the input, except that all preprocessing directive lines have been replaced with blank lines and all comments with spaces. Long runs of blank lines are discarded. The ISO standard specifies that it is implementation defined whether a preprocessor preserves whitespace between tokens, or replaces it with e.g.@: a single space. In GNU CPP, whitespace between tokens is collapsed to become a single space, with the exception that the first token on a non-directive line is preceded with sufficient spaces that it appears in the same column in the preprocessed output that it appeared in the original source file. This is so the output is easy to read. @xref{Differences from previous versions}. CPP does not insert any whitespace where there was none in the original source, except where necessary to prevent an accidental token paste. @cindex linemarkers Source file name and line number information is conveyed by lines of the form @smallexample # @var{linenum} @var{filename} @var{flags} @end smallexample @noindent These are called @dfn{linemarkers}. They are inserted as needed into the output (but never within a string or character constant). They mean that the following line originated in file @var{filename} at line @var{linenum}. @var{filename} will never contain any non-printing characters; they are replaced with octal escape sequences. After the file name comes zero or more flags, which are @samp{1}, @samp{2}, @samp{3}, or @samp{4}. If there are multiple flags, spaces separate them. Here is what the flags mean: @table @samp @item 1 This indicates the start of a new file. @item 2 This indicates returning to a file (after having included another file). @item 3 This indicates that the following text comes from a system header file, so certain warnings should be suppressed. @item 4 This indicates that the following text should be treated as being wrapped in an implicit @code{extern "C"} block. @c maybe cross reference NO_IMPLICIT_EXTERN_C @end table As an extension, the preprocessor accepts linemarkers in non-assembler input files. They are treated like the corresponding @samp{#line} directive, (@pxref{Line Control}), except that trailing flags are permitted, and are interpreted with the meanings described above. If multiple flags are given, they must be in ascending order. Some directives may be duplicated in the output of the preprocessor. These are @samp{#ident} (always), @samp{#pragma} (only if the preprocessor does not handle the pragma itself), and @samp{#define} and @samp{#undef} (with certain debugging options). If this happens, the @samp{#} of the directive will always be in the first column, and there will be no space between the @samp{#} and the directive name. If macro expansion happens to generate tokens which might be mistaken for a duplicated directive, a space will be inserted between the @samp{#} and the directive name. @node Traditional Mode @chapter Traditional Mode Traditional (pre-standard) C preprocessing is rather different from the preprocessing specified by the standard. When GCC is given the @option{-traditional-cpp} option, it attempts to emulate a traditional preprocessor. GCC versions 3.2 and later only support traditional mode semantics in the preprocessor, and not in the compiler front ends. This chapter outlines the traditional preprocessor semantics we implemented. The implementation does not correspond precisely to the behavior of earlier versions of GCC, nor to any true traditional preprocessor. After all, inconsistencies among traditional implementations were a major motivation for C standardization. However, we intend that it should be compatible with true traditional preprocessors in all ways that actually matter. @menu * Traditional lexical analysis:: * Traditional macros:: * Traditional miscellany:: * Traditional warnings:: @end menu @node Traditional lexical analysis @section Traditional lexical analysis The traditional preprocessor does not decompose its input into tokens the same way a standards-conforming preprocessor does. The input is simply treated as a stream of text with minimal internal form. This implementation does not treat trigraphs (@pxref{trigraphs}) specially since they were an invention of the standards committee. It handles arbitrarily-positioned escaped newlines properly and splices the lines as you would expect; many traditional preprocessors did not do this. The form of horizontal whitespace in the input file is preserved in the output. In particular, hard tabs remain hard tabs. This can be useful if, for example, you are preprocessing a Makefile. Traditional CPP only recognizes C-style block comments, and treats the @samp{/*} sequence as introducing a comment only if it lies outside quoted text. Quoted text is introduced by the usual single and double quotes, and also by an initial @samp{<} in a @code{#include} directive. Traditionally, comments are completely removed and are not replaced with a space. Since a traditional compiler does its own tokenization of the output of the preprocessor, this means that comments can effectively be used as token paste operators. However, comments behave like separators for text handled by the preprocessor itself, since it doesn't re-lex its input. For example, in @smallexample #if foo/**/bar @end smallexample @noindent @samp{foo} and @samp{bar} are distinct identifiers and expanded separately if they happen to be macros. In other words, this directive is equivalent to @smallexample #if foo bar @end smallexample @noindent rather than @smallexample #if foobar @end smallexample Generally speaking, in traditional mode an opening quote need not have a matching closing quote. In particular, a macro may be defined with replacement text that contains an unmatched quote. Of course, if you attempt to compile preprocessed output containing an unmatched quote you will get a syntax error. However, all preprocessing directives other than @code{#define} require matching quotes. For example: @smallexample #define m This macro's fine and has an unmatched quote "/* This is not a comment. */ /* @r{This is a comment. The following #include directive is ill-formed.} */ #include . .tr \(*W-|\(bv\*(Tr .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' 'br\} .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .\" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .hy 0 .if n .na .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "GCC 1" .TH GCC 1 "2011-03-07" "gcc-4.2.1" "GNU" .SH "NAME" gcc \- GNU project C and C++ compiler .SH "SYNOPSIS" .IX Header "SYNOPSIS" gcc [\fB\-c\fR|\fB\-S\fR|\fB\-E\fR] [\fB\-std=\fR\fIstandard\fR] [\fB\-g\fR] [\fB\-pg\fR] [\fB\-O\fR\fIlevel\fR] [\fB\-W\fR\fIwarn\fR...] [\fB\-pedantic\fR] [\fB\-I\fR\fIdir\fR...] [\fB\-L\fR\fIdir\fR...] [\fB\-D\fR\fImacro\fR[=\fIdefn\fR]...] [\fB\-U\fR\fImacro\fR] [\fB\-f\fR\fIoption\fR...] [\fB\-m\fR\fImachine-option\fR...] [\fB\-o\fR \fIoutfile\fR] [@\fIfile\fR] \fIinfile\fR... .PP Only the most useful options are listed here; see below for the remainder. \fBg++\fR accepts mostly the same options as \fBgcc\fR. .SH "DESCRIPTION" .IX Header "DESCRIPTION" When you invoke \s-1GCC\s0, it normally does preprocessing, compilation, assembly and linking. The \*(L"overall options\*(R" allow you to stop this process at an intermediate stage. For example, the \fB\-c\fR option says not to run the linker. Then the output consists of object files output by the assembler. .PP Other options are passed on to one stage of processing. Some options control the preprocessor and others the compiler itself. Yet other options control the assembler and linker; most of these are not documented here, since you rarely need to use any of them. .PP Most of the command line options that you can use with \s-1GCC\s0 are useful for C programs; when an option is only useful with another language (usually \*(C+), the explanation says so explicitly. If the description for a particular option does not mention a source language, you can use that option with all supported languages. .PP The \fBgcc\fR program accepts options and file names as operands. Many options have multi-letter names; therefore multiple single-letter options may \fInot\fR be grouped: \fB\-dr\fR is very different from \fB\-d\ \-r\fR. .PP You can mix options and other arguments. For the most part, the order you use doesn't matter. Order does matter when you use several options of the same kind; for example, if you specify \fB\-L\fR more than once, the directories are searched in the order specified. .PP Many options have long names starting with \fB\-f\fR or with \&\fB\-W\fR\-\-\-for example, \&\fB\-fmove\-loop\-invariants\fR, \fB\-Wformat\fR and so on. Most of these have both positive and negative forms; the negative form of \&\fB\-ffoo\fR would be \fB\-fno\-foo\fR. This manual documents only one of these two forms, whichever one is not the default. .SH "OPTIONS" .IX Header "OPTIONS" .Sh "Option Summary" .IX Subsection "Option Summary" Here is a summary of all the options, grouped by type. Explanations are in the following sections. .IP "\fIOverall Options\fR" 4 .IX Item "Overall Options" \&\fB\-c \-S \-E \-o\fR \fIfile\fR \fB\-combine \-pipe \-pass\-exit\-codes \&\-x\fR \fIlanguage\fR \fB\-v \-### \-\-help \-\-target\-help \-\-version @\fR\fIfile\fR .IP "\fIC Language Options\fR" 4 .IX Item "C Language Options" \&\fB\-ansi \-std=\fR\fIstandard\fR \fB\-fgnu89\-inline \&\-aux\-info\fR \fIfilename\fR \&\fB\-fno\-asm \-fno\-builtin \-fno\-builtin\-\fR\fIfunction\fR \&\fB\-fhosted \-ffreestanding \-fopenmp \-fms\-extensions \&\-trigraphs \-no\-integrated\-cpp \-traditional \-traditional\-cpp \&\-fallow\-single\-precision \-fcond\-mismatch \&\-fsigned\-bitfields \-fsigned\-char \&\-funsigned\-bitfields \-funsigned\-char\fR .IP "\fI\*(C+ Language Options\fR" 4 .IX Item " Language Options" \&\fB\-fabi\-version=\fR\fIn\fR \fB\-fno\-access\-control \-fcheck\-new \&\-fconserve\-space \-ffriend\-injection \&\-fno\-elide\-constructors \&\-fno\-enforce\-eh\-specs \&\-ffor\-scope \-fno\-for\-scope \-fno\-gnu\-keywords \&\-fno\-implicit\-templates \&\-fno\-implicit\-inline\-templates \&\-fno\-implement\-inlines \-fms\-extensions \&\-fno\-nonansi\-builtins \-fno\-operator\-names \&\-fno\-optional\-diags \-fpermissive \&\-frepo \-fno\-rtti \-fstats \-ftemplate\-depth\-\fR\fIn\fR \&\fB\-fno\-threadsafe\-statics \-fuse\-cxa\-atexit \-fno\-weak \-nostdinc++ \&\-fno\-default\-inline \-fvisibility\-inlines\-hidden \&\-Wabi \-Wctor\-dtor\-privacy \&\-Wnon\-virtual\-dtor \-Wreorder \&\-Weffc++ \-Wno\-deprecated \-Wstrict\-null\-sentinel \&\-Wno\-non\-template\-friend \-Wold\-style\-cast \&\-Woverloaded\-virtual \-Wno\-pmf\-conversions \&\-Wsign\-promo\fR .IP "\fILanguage Independent Options\fR" 4 .IX Item "Language Independent Options" \&\fB\-fmessage\-length=\fR\fIn\fR \&\fB\-fdiagnostics\-show\-location=\fR[\fBonce\fR|\fBevery-line\fR] \&\fB\-fdiagnostics\-show\-option\fR .IP "\fIWarning Options\fR" 4 .IX Item "Warning Options" \&\fB\-fsyntax\-only \-pedantic \-pedantic\-errors \&\-w \-Wextra \-Wall \-Waddress \-Waggregate\-return \-Wno\-attributes \&\-Wc++\-compat \-Wcast\-align \-Wcast\-qual \-Wchar\-subscripts \-Wcomment \&\-Wconversion \-Wno\-deprecated\-declarations \&\-Wdisabled\-optimization \-Wno\-div\-by\-zero \-Wno\-endif\-labels \&\-Werror \-Werror=* \-Werror\-implicit\-function\-declaration \&\-Wfatal\-errors \-Wfloat\-equal \-Wformat \-Wformat=2 \&\-Wno\-format\-extra\-args \-Wformat\-nonliteral \&\-Wformat\-security \-Wformat\-y2k \&\-Wimplicit \-Wimplicit\-function\-declaration \-Wimplicit\-int \&\-Wimport \-Wno\-import \-Winit\-self \-Winline \&\-Wno\-int\-to\-pointer\-cast \&\-Wno\-invalid\-offsetof \-Winvalid\-pch \&\-Wlarger\-than\-\fR\fIlen\fR \fB\-Wunsafe\-loop\-optimizations \-Wlong\-long \&\-Wmain \-Wmissing\-braces \-Wmissing\-field\-initializers \&\-Wmissing\-format\-attribute \-Wmissing\-include\-dirs \&\-Wmissing\-noreturn \&\-Wno\-multichar \-Wnonnull \-Wno\-overflow \&\-Woverlength\-strings \-Wpacked \-Wpadded \&\-Wparentheses \-Wpointer\-arith \-Wno\-pointer\-to\-int\-cast \&\-Wredundant\-decls \&\-Wreturn\-type \-Wsequence\-point \-Wshadow \&\-Wsign\-compare \-Wstack\-protector \&\-Wstrict\-aliasing \-Wstrict\-aliasing=2 \&\-Wstrict\-overflow \-Wstrict\-overflow=\fR\fIn\fR \&\fB\-Wswitch \-Wswitch\-default \-Wswitch\-enum \&\-Wsystem\-headers \-Wtrigraphs \-Wundef \-Wuninitialized \&\-Wunknown\-pragmas \-Wno\-pragmas \-Wunreachable\-code \&\-Wunused \-Wunused\-function \-Wunused\-label \-Wunused\-parameter \&\-Wunused\-value \-Wunused\-variable \-Wvariadic\-macros \&\-Wvolatile\-register\-var \-Wwrite\-strings\fR .IP "\fIC\-only Warning Options\fR" 4 .IX Item "C-only Warning Options" \&\fB\-Wbad\-function\-cast \-Wmissing\-declarations \&\-Wmissing\-prototypes \-Wnested\-externs \-Wold\-style\-definition \&\-Wstrict\-prototypes \-Wtraditional \&\-Wdeclaration\-after\-statement \-Wpointer\-sign\fR .IP "\fIDebugging Options\fR" 4 .IX Item "Debugging Options" \&\fB\-d\fR\fIletters\fR \fB\-dumpspecs \-dumpmachine \-dumpversion \&\-fdump\-noaddr \-fdump\-unnumbered \-fdump\-translation\-unit\fR[\fB\-\fR\fIn\fR] \&\fB\-fdump\-class\-hierarchy\fR[\fB\-\fR\fIn\fR] \&\fB\-fdump\-ipa\-all \-fdump\-ipa\-cgraph \&\-fdump\-tree\-all \&\-fdump\-tree\-original\fR[\fB\-\fR\fIn\fR] \&\fB\-fdump\-tree\-optimized\fR[\fB\-\fR\fIn\fR] \&\fB\-fdump\-tree\-inlined\fR[\fB\-\fR\fIn\fR] \&\fB\-fdump\-tree\-cfg \-fdump\-tree\-vcg \-fdump\-tree\-alias \&\-fdump\-tree\-ch \&\-fdump\-tree\-ssa\fR[\fB\-\fR\fIn\fR] \fB\-fdump\-tree\-pre\fR[\fB\-\fR\fIn\fR] \&\fB\-fdump\-tree\-ccp\fR[\fB\-\fR\fIn\fR] \fB\-fdump\-tree\-dce\fR[\fB\-\fR\fIn\fR] \&\fB\-fdump\-tree\-gimple\fR[\fB\-raw\fR] \fB\-fdump\-tree\-mudflap\fR[\fB\-\fR\fIn\fR] \&\fB\-fdump\-tree\-dom\fR[\fB\-\fR\fIn\fR] \&\fB\-fdump\-tree\-dse\fR[\fB\-\fR\fIn\fR] \&\fB\-fdump\-tree\-phiopt\fR[\fB\-\fR\fIn\fR] \&\fB\-fdump\-tree\-forwprop\fR[\fB\-\fR\fIn\fR] \&\fB\-fdump\-tree\-copyrename\fR[\fB\-\fR\fIn\fR] \&\fB\-fdump\-tree\-nrv \-fdump\-tree\-vect \&\-fdump\-tree\-sink \&\-fdump\-tree\-sra\fR[\fB\-\fR\fIn\fR] \&\fB\-fdump\-tree\-salias \&\-fdump\-tree\-fre\fR[\fB\-\fR\fIn\fR] \&\fB\-fdump\-tree\-vrp\fR[\fB\-\fR\fIn\fR] \&\fB\-ftree\-vectorizer\-verbose=\fR\fIn\fR \&\fB\-fdump\-tree\-storeccp\fR[\fB\-\fR\fIn\fR] \&\fB\-feliminate\-dwarf2\-dups \-feliminate\-unused\-debug\-types \&\-feliminate\-unused\-debug\-symbols \-femit\-class\-debug\-always \&\-fmem\-report \-fprofile\-arcs \&\-frandom\-seed=\fR\fIstring\fR \fB\-fsched\-verbose=\fR\fIn\fR \&\fB\-ftest\-coverage \-ftime\-report \-fvar\-tracking \&\-g \-g\fR\fIlevel\fR \fB\-gcoff \-gdwarf\-2 \&\-ggdb \-gstabs \-gstabs+ \-gvms \-gxcoff \-gxcoff+ \&\-p \-pg \-print\-file\-name=\fR\fIlibrary\fR \fB\-print\-libgcc\-file\-name \&\-print\-multi\-directory \-print\-multi\-lib \&\-print\-prog\-name=\fR\fIprogram\fR \fB\-print\-search\-dirs \-Q \&\-save\-temps \-time\fR .IP "\fIOptimization Options\fR" 4 .IX Item "Optimization Options" \&\fB\-falign\-functions=\fR\fIn\fR \fB\-falign\-jumps=\fR\fIn\fR \&\fB\-falign\-labels=\fR\fIn\fR \fB\-falign\-loops=\fR\fIn\fR \&\fB\-fbounds\-check \-fmudflap \-fmudflapth \-fmudflapir \&\-fbranch\-probabilities \-fprofile\-values \-fvpt \-fbranch\-target\-load\-optimize \&\-fbranch\-target\-load\-optimize2 \-fbtr\-bb\-exclusive \&\-fcaller\-saves \-fcprop\-registers \-fcse\-follow\-jumps \&\-fcse\-skip\-blocks \-fcx\-limited\-range \-fdata\-sections \&\-fdelayed\-branch \-fdelete\-null\-pointer\-checks \-fearly\-inlining \&\-fexpensive\-optimizations \-ffast\-math \-ffloat\-store \&\-fforce\-addr \-ffunction\-sections \&\-fgcse \-fgcse\-lm \-fgcse\-sm \-fgcse\-las \-fgcse\-after\-reload \&\-fcrossjumping \-fif\-conversion \-fif\-conversion2 \&\-finline\-functions \-finline\-functions\-called\-once \&\-finline\-limit=\fR\fIn\fR \fB\-fkeep\-inline\-functions \&\-fkeep\-static\-consts \-fmerge\-constants \-fmerge\-all\-constants \&\-fmodulo\-sched \-fno\-branch\-count\-reg \&\-fno\-default\-inline \-fno\-defer\-pop \-fmove\-loop\-invariants \&\-fno\-function\-cse \-fno\-guess\-branch\-probability \&\-fno\-inline \-fno\-math\-errno \-fno\-peephole \-fno\-peephole2 \&\-funsafe\-math\-optimizations \-funsafe\-loop\-optimizations \-ffinite\-math\-only \&\-fno\-toplevel\-reorder \-fno\-trapping\-math \-fno\-zero\-initialized\-in\-bss \&\-fomit\-frame\-pointer \-foptimize\-register\-move \&\-foptimize\-sibling\-calls \-fprefetch\-loop\-arrays \&\-fprofile\-generate \-fprofile\-use \&\-fregmove \-frename\-registers \&\-freorder\-blocks \-freorder\-blocks\-and\-partition \-freorder\-functions \&\-frerun\-cse\-after\-loop \&\-frounding\-math \-frtl\-abstract\-sequences \&\-fschedule\-insns \-fschedule\-insns2 \&\-fno\-sched\-interblock \-fno\-sched\-spec \-fsched\-spec\-load \&\-fsched\-spec\-load\-dangerous \&\-fsched\-stalled\-insns=\fR\fIn\fR \fB\-fsched\-stalled\-insns\-dep=\fR\fIn\fR \&\fB\-fsched2\-use\-superblocks \&\-fsched2\-use\-traces \-fsee \-freschedule\-modulo\-scheduled\-loops \&\-fsection\-anchors \-fsignaling\-nans \-fsingle\-precision\-constant -\&\-fstack\-protector \-fstack\-protector\-all +\&\-fstack\-protector \-fstack\-protector\-all \-fstack\-protector\-strong \&\-fstrict\-aliasing \-fstrict\-overflow \-ftracer \-fthread\-jumps \&\-funroll\-all\-loops \-funroll\-loops \-fpeel\-loops \&\-fsplit\-ivs\-in\-unroller \-funswitch\-loops \&\-fvariable\-expansion\-in\-unroller \&\-ftree\-pre \-ftree\-ccp \-ftree\-dce \-ftree\-loop\-optimize \&\-ftree\-loop\-linear \-ftree\-loop\-im \-ftree\-loop\-ivcanon \-fivopts \&\-ftree\-dominator\-opts \-ftree\-dse \-ftree\-copyrename \-ftree\-sink \&\-ftree\-ch \-ftree\-sra \-ftree\-ter \-ftree\-lrs \-ftree\-fre \-ftree\-vectorize \&\-ftree\-vect\-loop\-version \-ftree\-salias \-fipa\-pta \-fweb \&\-ftree\-copy\-prop \-ftree\-store\-ccp \-ftree\-store\-copy\-prop \-fwhole\-program \&\-\-param\fR \fIname\fR\fB=\fR\fIvalue\fR \&\fB\-O \-O0 \-O1 \-O2 \-O3 \-Os\fR .IP "\fIPreprocessor Options\fR" 4 .IX Item "Preprocessor Options" \&\fB\-A\fR\fIquestion\fR\fB=\fR\fIanswer\fR \&\fB\-A\-\fR\fIquestion\fR[\fB=\fR\fIanswer\fR] \&\fB\-C \-dD \-dI \-dM \-dN \&\-D\fR\fImacro\fR[\fB=\fR\fIdefn\fR] \fB\-E \-H \&\-idirafter\fR \fIdir\fR \&\fB\-include\fR \fIfile\fR \fB\-imacros\fR \fIfile\fR \&\fB\-iprefix\fR \fIfile\fR \fB\-iwithprefix\fR \fIdir\fR \&\fB\-iwithprefixbefore\fR \fIdir\fR \fB\-isystem\fR \fIdir\fR \&\fB\-imultilib\fR \fIdir\fR \fB\-isysroot\fR \fIdir\fR \&\fB\-M \-MM \-MF \-MG \-MP \-MQ \-MT \-nostdinc \&\-P \-fworking\-directory \-remap \&\-trigraphs \-undef \-U\fR\fImacro\fR \fB\-Wp,\fR\fIoption\fR \&\fB\-Xpreprocessor\fR \fIoption\fR .IP "\fIAssembler Option\fR" 4 .IX Item "Assembler Option" \&\fB\-Wa,\fR\fIoption\fR \fB\-Xassembler\fR \fIoption\fR .IP "\fILinker Options\fR" 4 .IX Item "Linker Options" \&\fIobject-file-name\fR \fB\-l\fR\fIlibrary\fR \&\fB\-nostartfiles \-nodefaultlibs \-nostdlib \-pie \-rdynamic \&\-s \-static \-static\-libgcc \-shared \-shared\-libgcc \-symbolic \&\-Wl,\fR\fIoption\fR \fB\-Xlinker\fR \fIoption\fR \&\fB\-u\fR \fIsymbol\fR .IP "\fIDirectory Options\fR" 4 .IX Item "Directory Options" \&\fB\-B\fR\fIprefix\fR \fB\-I\fR\fIdir\fR \fB\-iquote\fR\fIdir\fR \fB\-L\fR\fIdir\fR \&\fB\-specs=\fR\fIfile\fR \fB\-I\- \-\-sysroot=\fR\fIdir\fR .IP "\fITarget Options\fR" 4 .IX Item "Target Options" \&\fB\-V\fR \fIversion\fR \fB\-b\fR \fImachine\fR .IP "\fIMachine Dependent Options\fR" 4 .IX Item "Machine Dependent Options" \&\fI\s-1ARC\s0 Options\fR \&\fB\-EB \-EL \&\-mmangle\-cpu \-mcpu=\fR\fIcpu\fR \fB\-mtext=\fR\fItext-section\fR \&\fB\-mdata=\fR\fIdata-section\fR \fB\-mrodata=\fR\fIreadonly-data-section\fR .Sp \&\fI\s-1ARM\s0 Options\fR \&\fB\-mapcs\-frame \-mno\-apcs\-frame \&\-mabi=\fR\fIname\fR \&\fB\-mapcs\-stack\-check \-mno\-apcs\-stack\-check \&\-mapcs\-float \-mno\-apcs\-float \&\-mapcs\-reentrant \-mno\-apcs\-reentrant \&\-msched\-prolog \-mno\-sched\-prolog \&\-mlittle\-endian \-mbig\-endian \-mwords\-little\-endian \&\-mfloat\-abi=\fR\fIname\fR \fB\-msoft\-float \-mhard\-float \-mfpe \&\-mthumb\-interwork \-mno\-thumb\-interwork \&\-mcpu=\fR\fIname\fR \fB\-march=\fR\fIname\fR \fB\-mfpu=\fR\fIname\fR \&\fB\-mstructure\-size\-boundary=\fR\fIn\fR \&\fB\-mabort\-on\-noreturn \&\-mlong\-calls \-mno\-long\-calls \&\-msingle\-pic\-base \-mno\-single\-pic\-base \&\-mpic\-register=\fR\fIreg\fR \&\fB\-mnop\-fun\-dllimport \&\-mcirrus\-fix\-invalid\-insns \-mno\-cirrus\-fix\-invalid\-insns \&\-mpoke\-function\-name \&\-mthumb \-marm \&\-mtpcs\-frame \-mtpcs\-leaf\-frame \&\-mcaller\-super\-interworking \-mcallee\-super\-interworking \&\-mtp=\fR\fIname\fR .Sp \&\fI\s-1AVR\s0 Options\fR \&\fB\-mmcu=\fR\fImcu\fR \fB\-msize \-minit\-stack=\fR\fIn\fR \fB\-mno\-interrupts \&\-mcall\-prologues \-mno\-tablejump \-mtiny\-stack \-mint8\fR .Sp \&\fIBlackfin Options\fR \&\fB\-momit\-leaf\-frame\-pointer \-mno\-omit\-leaf\-frame\-pointer \&\-mspecld\-anomaly \-mno\-specld\-anomaly \-mcsync\-anomaly \-mno\-csync\-anomaly \&\-mlow\-64k \-mno\-low64k \-mid\-shared\-library \&\-mno\-id\-shared\-library \-mshared\-library\-id=\fR\fIn\fR \&\fB\-mlong\-calls \-mno\-long\-calls\fR .Sp \&\fI\s-1CRIS\s0 Options\fR \&\fB\-mcpu=\fR\fIcpu\fR \fB\-march=\fR\fIcpu\fR \fB\-mtune=\fR\fIcpu\fR \&\fB\-mmax\-stack\-frame=\fR\fIn\fR \fB\-melinux\-stacksize=\fR\fIn\fR \&\fB\-metrax4 \-metrax100 \-mpdebug \-mcc\-init \-mno\-side\-effects \&\-mstack\-align \-mdata\-align \-mconst\-align \&\-m32\-bit \-m16\-bit \-m8\-bit \-mno\-prologue\-epilogue \-mno\-gotplt \&\-melf \-maout \-melinux \-mlinux \-sim \-sim2 \&\-mmul\-bug\-workaround \-mno\-mul\-bug\-workaround\fR .Sp \&\fI\s-1CRX\s0 Options\fR \&\fB\-mmac \-mpush\-args\fR .Sp \&\fIDarwin Options\fR \&\fB\-all_load \-allowable_client \-arch \-arch_errors_fatal \&\-arch_only \-bind_at_load \-bundle \-bundle_loader \&\-client_name \-compatibility_version \-current_version \&\-dead_strip \&\-dependency\-file \-dylib_file \-dylinker_install_name \&\-dynamic \-dynamiclib \-exported_symbols_list \&\-filelist \-flat_namespace \-force_cpusubtype_ALL \&\-force_flat_namespace \-headerpad_max_install_names \&\-image_base \-init \-install_name \-keep_private_externs \&\-multi_module \-multiply_defined \-multiply_defined_unused \&\-noall_load \-no_dead_strip_inits_and_terms \&\-nofixprebinding \-nomultidefs \-noprebind \-noseglinkedit \&\-pagezero_size \-prebind \-prebind_all_twolevel_modules \&\-private_bundle \-read_only_relocs \-sectalign \&\-sectobjectsymbols \-whyload \-seg1addr \&\-sectcreate \-sectobjectsymbols \-sectorder \&\-segaddr \-segs_read_only_addr \-segs_read_write_addr \&\-seg_addr_table \-seg_addr_table_filename \-seglinkedit \&\-segprot \-segs_read_only_addr \-segs_read_write_addr \&\-single_module \-static \-sub_library \-sub_umbrella \&\-twolevel_namespace \-umbrella \-undefined \&\-unexported_symbols_list \-weak_reference_mismatches \&\-whatsloaded \-F \-gused \-gfull \-mmacosx\-version\-min=\fR\fIversion\fR \&\fB\-mkernel \-mone\-byte\-bool\fR .Sp \&\fI\s-1DEC\s0 Alpha Options\fR \&\fB\-mno\-fp\-regs \-msoft\-float \-malpha\-as \-mgas \&\-mieee \-mieee\-with\-inexact \-mieee\-conformant \&\-mfp\-trap\-mode=\fR\fImode\fR \fB\-mfp\-rounding\-mode=\fR\fImode\fR \&\fB\-mtrap\-precision=\fR\fImode\fR \fB\-mbuild\-constants \&\-mcpu=\fR\fIcpu-type\fR \fB\-mtune=\fR\fIcpu-type\fR \&\fB\-mbwx \-mmax \-mfix \-mcix \&\-mfloat\-vax \-mfloat\-ieee \&\-mexplicit\-relocs \-msmall\-data \-mlarge\-data \&\-msmall\-text \-mlarge\-text \&\-mmemory\-latency=\fR\fItime\fR .Sp \&\fI\s-1DEC\s0 Alpha/VMS Options\fR \&\fB\-mvms\-return\-codes\fR .Sp \&\fI\s-1FRV\s0 Options\fR \&\fB\-mgpr\-32 \-mgpr\-64 \-mfpr\-32 \-mfpr\-64 \&\-mhard\-float \-msoft\-float \&\-malloc\-cc \-mfixed\-cc \-mdword \-mno\-dword \&\-mdouble \-mno\-double \&\-mmedia \-mno\-media \-mmuladd \-mno\-muladd \&\-mfdpic \-minline\-plt \-mgprel\-ro \-multilib\-library\-pic \&\-mlinked\-fp \-mlong\-calls \-malign\-labels \&\-mlibrary\-pic \-macc\-4 \-macc\-8 \&\-mpack \-mno\-pack \-mno\-eflags \-mcond\-move \-mno\-cond\-move \&\-moptimize\-membar \-mno\-optimize\-membar \&\-mscc \-mno\-scc \-mcond\-exec \-mno\-cond\-exec \&\-mvliw\-branch \-mno\-vliw\-branch \&\-mmulti\-cond\-exec \-mno\-multi\-cond\-exec \-mnested\-cond\-exec \&\-mno\-nested\-cond\-exec \-mtomcat\-stats \&\-mTLS \-mtls \&\-mcpu=\fR\fIcpu\fR .Sp \&\fIGNU/Linux Options\fR \&\fB\-muclibc\fR .Sp \&\fIH8/300 Options\fR \&\fB\-mrelax \-mh \-ms \-mn \-mint32 \-malign\-300\fR .Sp \&\fI\s-1HPPA\s0 Options\fR \&\fB\-march=\fR\fIarchitecture-type\fR \&\fB\-mbig\-switch \-mdisable\-fpregs \-mdisable\-indexing \&\-mfast\-indirect\-calls \-mgas \-mgnu\-ld \-mhp\-ld \&\-mfixed\-range=\fR\fIregister-range\fR \&\fB\-mjump\-in\-delay \-mlinker\-opt \-mlong\-calls \&\-mlong\-load\-store \-mno\-big\-switch \-mno\-disable\-fpregs \&\-mno\-disable\-indexing \-mno\-fast\-indirect\-calls \-mno\-gas \&\-mno\-jump\-in\-delay \-mno\-long\-load\-store \&\-mno\-portable\-runtime \-mno\-soft\-float \&\-mno\-space\-regs \-msoft\-float \-mpa\-risc\-1\-0 \&\-mpa\-risc\-1\-1 \-mpa\-risc\-2\-0 \-mportable\-runtime \&\-mschedule=\fR\fIcpu-type\fR \fB\-mspace\-regs \-msio \-mwsio \&\-munix=\fR\fIunix-std\fR \fB\-nolibdld \-static \-threads\fR .Sp \&\fIi386 and x86\-64 Options\fR \&\fB\-mtune=\fR\fIcpu-type\fR \fB\-march=\fR\fIcpu-type\fR \&\fB\-mfpmath=\fR\fIunit\fR \&\fB\-masm=\fR\fIdialect\fR \fB\-mno\-fancy\-math\-387 \&\-mno\-fp\-ret\-in\-387 \-msoft\-float \-msvr3\-shlib \&\-mno\-wide\-multiply \-mrtd \-malign\-double \&\-mpreferred\-stack\-boundary=\fR\fInum\fR \&\fB\-mmmx \-msse \-msse2 \-msse3 \-mssse3 \-m3dnow \&\-mthreads \-mno\-align\-stringops \-minline\-all\-stringops \&\-mpush\-args \-maccumulate\-outgoing\-args \-m128bit\-long\-double \&\-m96bit\-long\-double \-mregparm=\fR\fInum\fR \fB\-msseregparm \&\-mstackrealign \&\-momit\-leaf\-frame\-pointer \-mno\-red\-zone \-mno\-tls\-direct\-seg\-refs \&\-mcmodel=\fR\fIcode-model\fR \&\fB\-m32 \-m64 \-mlarge\-data\-threshold=\fR\fInum\fR .Sp \&\fI\s-1IA\-64\s0 Options\fR \&\fB\-mbig\-endian \-mlittle\-endian \-mgnu\-as \-mgnu\-ld \-mno\-pic \&\-mvolatile\-asm\-stop \-mregister\-names \-mno\-sdata \&\-mconstant\-gp \-mauto\-pic \-minline\-float\-divide\-min\-latency \&\-minline\-float\-divide\-max\-throughput \&\-minline\-int\-divide\-min\-latency \&\-minline\-int\-divide\-max\-throughput \&\-minline\-sqrt\-min\-latency \-minline\-sqrt\-max\-throughput \&\-mno\-dwarf2\-asm \-mearly\-stop\-bits \&\-mfixed\-range=\fR\fIregister-range\fR \fB\-mtls\-size=\fR\fItls-size\fR \&\fB\-mtune=\fR\fIcpu-type\fR \fB\-mt \-pthread \-milp32 \-mlp64 \&\-mno\-sched\-br\-data\-spec \-msched\-ar\-data\-spec \-mno\-sched\-control\-spec \&\-msched\-br\-in\-data\-spec \-msched\-ar\-in\-data\-spec \-msched\-in\-control\-spec \&\-msched\-ldc \-mno\-sched\-control\-ldc \-mno\-sched\-spec\-verbose \&\-mno\-sched\-prefer\-non\-data\-spec\-insns \&\-mno\-sched\-prefer\-non\-control\-spec\-insns \&\-mno\-sched\-count\-spec\-in\-critical\-path\fR .Sp \&\fIM32R/D Options\fR \&\fB\-m32r2 \-m32rx \-m32r \&\-mdebug \&\-malign\-loops \-mno\-align\-loops \&\-missue\-rate=\fR\fInumber\fR \&\fB\-mbranch\-cost=\fR\fInumber\fR \&\fB\-mmodel=\fR\fIcode-size-model-type\fR \&\fB\-msdata=\fR\fIsdata-type\fR \&\fB\-mno\-flush\-func \-mflush\-func=\fR\fIname\fR \&\fB\-mno\-flush\-trap \-mflush\-trap=\fR\fInumber\fR \&\fB\-G\fR \fInum\fR .Sp \&\fIM32C Options\fR \&\fB\-mcpu=\fR\fIcpu\fR \fB\-msim \-memregs=\fR\fInumber\fR .Sp \&\fIM680x0 Options\fR \&\fB\-m68000 \-m68020 \-m68020\-40 \-m68020\-60 \-m68030 \-m68040 \&\-m68060 \-mcpu32 \-m5200 \-mcfv4e \-m68881 \-mbitfield \&\-mc68000 \-mc68020 \&\-mnobitfield \-mrtd \-mshort \-msoft\-float \-mpcrel \&\-malign\-int \-mstrict\-align \-msep\-data \-mno\-sep\-data \&\-mshared\-library\-id=n \-mid\-shared\-library \-mno\-id\-shared\-library\fR .Sp \&\fIM68hc1x Options\fR \&\fB\-m6811 \-m6812 \-m68hc11 \-m68hc12 \-m68hcs12 \&\-mauto\-incdec \-minmax \-mlong\-calls \-mshort \&\-msoft\-reg\-count=\fR\fIcount\fR .Sp \&\fIMCore Options\fR \&\fB\-mhardlit \-mno\-hardlit \-mdiv \-mno\-div \-mrelax\-immediates \&\-mno\-relax\-immediates \-mwide\-bitfields \-mno\-wide\-bitfields \&\-m4byte\-functions \-mno\-4byte\-functions \-mcallgraph\-data \&\-mno\-callgraph\-data \-mslow\-bytes \-mno\-slow\-bytes \-mno\-lsim \&\-mlittle\-endian \-mbig\-endian \-m210 \-m340 \-mstack\-increment\fR .Sp \&\fI\s-1MIPS\s0 Options\fR \&\fB\-EL \-EB \-march=\fR\fIarch\fR \fB\-mtune=\fR\fIarch\fR \&\fB\-mips1 \-mips2 \-mips3 \-mips4 \-mips32 \-mips32r2 \-mips64 \&\-mips16 \-mno\-mips16 \-mabi=\fR\fIabi\fR \fB\-mabicalls \-mno\-abicalls \&\-mshared \-mno\-shared \-mxgot \-mno\-xgot \-mgp32 \-mgp64 \&\-mfp32 \-mfp64 \-mhard\-float \-msoft\-float \&\-msingle\-float \-mdouble\-float \-mdsp \-mpaired\-single \-mips3d \&\-mlong64 \-mlong32 \-msym32 \-mno\-sym32 \&\-G\fR\fInum\fR \fB\-membedded\-data \-mno\-embedded\-data \&\-muninit\-const\-in\-rodata \-mno\-uninit\-const\-in\-rodata \&\-msplit\-addresses \-mno\-split\-addresses \&\-mexplicit\-relocs \-mno\-explicit\-relocs \&\-mcheck\-zero\-division \-mno\-check\-zero\-division \&\-mdivide\-traps \-mdivide\-breaks \&\-mmemcpy \-mno\-memcpy \-mlong\-calls \-mno\-long\-calls \&\-mmad \-mno\-mad \-mfused\-madd \-mno\-fused\-madd \-nocpp \&\-mfix\-r4000 \-mno\-fix\-r4000 \-mfix\-r4400 \-mno\-fix\-r4400 \&\-mfix\-vr4120 \-mno\-fix\-vr4120 \-mfix\-vr4130 \&\-mfix\-sb1 \-mno\-fix\-sb1 \&\-mflush\-func=\fR\fIfunc\fR \fB\-mno\-flush\-func \&\-mbranch\-likely \-mno\-branch\-likely \&\-mfp\-exceptions \-mno\-fp\-exceptions \&\-mvr4130\-align \-mno\-vr4130\-align\fR .Sp \&\fI\s-1MMIX\s0 Options\fR \&\fB\-mlibfuncs \-mno\-libfuncs \-mepsilon \-mno\-epsilon \-mabi=gnu \&\-mabi=mmixware \-mzero\-extend \-mknuthdiv \-mtoplevel\-symbols \&\-melf \-mbranch\-predict \-mno\-branch\-predict \-mbase\-addresses \&\-mno\-base\-addresses \-msingle\-exit \-mno\-single\-exit\fR .Sp \&\fI\s-1MN10300\s0 Options\fR \&\fB\-mmult\-bug \-mno\-mult\-bug \&\-mam33 \-mno\-am33 \&\-mam33\-2 \-mno\-am33\-2 \&\-mreturn\-pointer\-on\-d0 \&\-mno\-crt0 \-mrelax\fR .Sp \&\fI\s-1MT\s0 Options\fR \&\fB\-mno\-crt0 \-mbacc \-msim \&\-march=\fR\fIcpu-type\fR\fB \fR .Sp \&\fI\s-1PDP\-11\s0 Options\fR \&\fB\-mfpu \-msoft\-float \-mac0 \-mno\-ac0 \-m40 \-m45 \-m10 \&\-mbcopy \-mbcopy\-builtin \-mint32 \-mno\-int16 \&\-mint16 \-mno\-int32 \-mfloat32 \-mno\-float64 \&\-mfloat64 \-mno\-float32 \-mabshi \-mno\-abshi \&\-mbranch\-expensive \-mbranch\-cheap \&\-msplit \-mno\-split \-munix\-asm \-mdec\-asm\fR .Sp \&\fIPowerPC Options\fR See \s-1RS/6000\s0 and PowerPC Options. .Sp \&\fI\s-1RS/6000\s0 and PowerPC Options\fR \&\fB\-mcpu=\fR\fIcpu-type\fR \&\fB\-mtune=\fR\fIcpu-type\fR \&\fB\-mpower \-mno\-power \-mpower2 \-mno\-power2 \&\-mpowerpc \-mpowerpc64 \-mno\-powerpc \&\-maltivec \-mno\-altivec \&\-mpowerpc\-gpopt \-mno\-powerpc\-gpopt \&\-mpowerpc\-gfxopt \-mno\-powerpc\-gfxopt \&\-mmfcrf \-mno\-mfcrf \-mpopcntb \-mno\-popcntb \-mfprnd \-mno\-fprnd \&\-mnew\-mnemonics \-mold\-mnemonics \&\-mfull\-toc \-mminimal\-toc \-mno\-fp\-in\-toc \-mno\-sum\-in\-toc \&\-m64 \-m32 \-mxl\-compat \-mno\-xl\-compat \-mpe \&\-malign\-power \-malign\-natural \&\-msoft\-float \-mhard\-float \-mmultiple \-mno\-multiple \&\-mstring \-mno\-string \-mupdate \-mno\-update \&\-mfused\-madd \-mno\-fused\-madd \-mbit\-align \-mno\-bit\-align \&\-mstrict\-align \-mno\-strict\-align \-mrelocatable \&\-mno\-relocatable \-mrelocatable\-lib \-mno\-relocatable\-lib \&\-mtoc \-mno\-toc \-mlittle \-mlittle\-endian \-mbig \-mbig\-endian \&\-mdynamic\-no\-pic \-maltivec \-mswdiv \&\-mprioritize\-restricted\-insns=\fR\fIpriority\fR \&\fB\-msched\-costly\-dep=\fR\fIdependence_type\fR \&\fB\-minsert\-sched\-nops=\fR\fIscheme\fR \&\fB\-mcall\-sysv \-mcall\-netbsd \&\-maix\-struct\-return \-msvr4\-struct\-return \&\-mabi=\fR\fIabi-type\fR \fB\-msecure\-plt \-mbss\-plt \&\-misel \-mno\-isel \&\-misel=yes \-misel=no \&\-mspe \-mno\-spe \&\-mspe=yes \-mspe=no \&\-mvrsave \-mno\-vrsave \&\-mmulhw \-mno\-mulhw \&\-mdlmzb \-mno\-dlmzb \&\-mfloat\-gprs=yes \-mfloat\-gprs=no \-mfloat\-gprs=single \-mfloat\-gprs=double \&\-mprototype \-mno\-prototype \&\-msim \-mmvme \-mads \-myellowknife \-memb \-msdata \&\-msdata=\fR\fIopt\fR \fB\-mvxworks \-mwindiss \-G\fR \fInum\fR \fB\-pthread\fR .Sp \&\fIS/390 and zSeries Options\fR \&\fB\-mtune=\fR\fIcpu-type\fR \fB\-march=\fR\fIcpu-type\fR \&\fB\-mhard\-float \-msoft\-float \-mlong\-double\-64 \-mlong\-double\-128 \&\-mbackchain \-mno\-backchain \-mpacked\-stack \-mno\-packed\-stack \&\-msmall\-exec \-mno\-small\-exec \-mmvcle \-mno\-mvcle \&\-m64 \-m31 \-mdebug \-mno\-debug \-mesa \-mzarch \&\-mtpf\-trace \-mno\-tpf\-trace \-mfused\-madd \-mno\-fused\-madd \&\-mwarn\-framesize \-mwarn\-dynamicstack \-mstack\-size \-mstack\-guard\fR .Sp \&\fIScore Options\fR \&\fB\-meb \-mel \&\-mnhwloop \&\-muls \&\-mmac \&\-mscore5 \-mscore5u \-mscore7 \-mscore7d\fR .Sp \&\fI\s-1SH\s0 Options\fR \&\fB\-m1 \-m2 \-m2e \-m3 \-m3e \&\-m4\-nofpu \-m4\-single\-only \-m4\-single \-m4 \&\-m4a\-nofpu \-m4a\-single\-only \-m4a\-single \-m4a \-m4al \&\-m5\-64media \-m5\-64media\-nofpu \&\-m5\-32media \-m5\-32media\-nofpu \&\-m5\-compact \-m5\-compact\-nofpu \&\-mb \-ml \-mdalign \-mrelax \&\-mbigtable \-mfmovd \-mhitachi \-mrenesas \-mno\-renesas \-mnomacsave \&\-mieee \-misize \-mpadstruct \-mspace \&\-mprefergot \-musermode \-multcost=\fR\fInumber\fR \fB\-mdiv=\fR\fIstrategy\fR \&\fB\-mdivsi3_libfunc=\fR\fIname\fR \&\fB\-madjust\-unroll \-mindexed\-addressing \-mgettrcost=\fR\fInumber\fR \fB\-mpt\-fixed \-minvalid\-symbols\fR .Sp \&\fI\s-1SPARC\s0 Options\fR \&\fB\-mcpu=\fR\fIcpu-type\fR \&\fB\-mtune=\fR\fIcpu-type\fR \&\fB\-mcmodel=\fR\fIcode-model\fR \&\fB\-m32 \-m64 \-mapp\-regs \-mno\-app\-regs \&\-mfaster\-structs \-mno\-faster\-structs \&\-mfpu \-mno\-fpu \-mhard\-float \-msoft\-float \&\-mhard\-quad\-float \-msoft\-quad\-float \&\-mimpure\-text \-mno\-impure\-text \-mlittle\-endian \&\-mstack\-bias \-mno\-stack\-bias \&\-munaligned\-doubles \-mno\-unaligned\-doubles \&\-mv8plus \-mno\-v8plus \-mvis \-mno\-vis \&\-threads \-pthreads \-pthread\fR .Sp \&\fISystem V Options\fR \&\fB\-Qy \-Qn \-YP,\fR\fIpaths\fR \fB\-Ym,\fR\fIdir\fR .Sp \&\fITMS320C3x/C4x Options\fR \&\fB\-mcpu=\fR\fIcpu\fR \fB\-mbig \-msmall \-mregparm \-mmemparm \&\-mfast\-fix \-mmpyi \-mbk \-mti \-mdp\-isr\-reload \&\-mrpts=\fR\fIcount\fR \fB\-mrptb \-mdb \-mloop\-unsigned \&\-mparallel\-insns \-mparallel\-mpy \-mpreserve\-float\fR .Sp \&\fIV850 Options\fR \&\fB\-mlong\-calls \-mno\-long\-calls \-mep \-mno\-ep \&\-mprolog\-function \-mno\-prolog\-function \-mspace \&\-mtda=\fR\fIn\fR \fB\-msda=\fR\fIn\fR \fB\-mzda=\fR\fIn\fR \&\fB\-mapp\-regs \-mno\-app\-regs \&\-mdisable\-callt \-mno\-disable\-callt \&\-mv850e1 \&\-mv850e \&\-mv850 \-mbig\-switch\fR .Sp \&\fI\s-1VAX\s0 Options\fR \&\fB\-mg \-mgnu \-munix\fR .Sp \&\fIx86\-64 Options\fR See i386 and x86\-64 Options. .Sp \&\fIXstormy16 Options\fR \&\fB\-msim\fR .Sp \&\fIXtensa Options\fR \&\fB\-mconst16 \-mno\-const16 \&\-mfused\-madd \-mno\-fused\-madd \&\-mtext\-section\-literals \-mno\-text\-section\-literals \&\-mtarget\-align \-mno\-target\-align \&\-mlongcalls \-mno\-longcalls\fR .Sp \&\fIzSeries Options\fR See S/390 and zSeries Options. .IP "\fICode Generation Options\fR" 4 .IX Item "Code Generation Options" \&\fB\-fcall\-saved\-\fR\fIreg\fR \fB\-fcall\-used\-\fR\fIreg\fR \&\fB\-ffixed\-\fR\fIreg\fR \fB\-fexceptions \&\-fnon\-call\-exceptions \-funwind\-tables \&\-fasynchronous\-unwind\-tables \&\-finhibit\-size\-directive \-finstrument\-functions \&\-fno\-common \-fno\-ident \&\-fpcc\-struct\-return \-fpic \-fPIC \-fpie \-fPIE \&\-fno\-jump\-tables \&\-freg\-struct\-return \-fshort\-enums \&\-fshort\-double \-fshort\-wchar \&\-fverbose\-asm \-fpack\-struct[=\fR\fIn\fR\fB] \-fstack\-check \&\-fstack\-limit\-register=\fR\fIreg\fR \fB\-fstack\-limit\-symbol=\fR\fIsym\fR \&\fB\-fargument\-alias \-fargument\-noalias \&\-fargument\-noalias\-global \-fargument\-noalias\-anything \&\-fleading\-underscore \-ftls\-model=\fR\fImodel\fR \&\fB\-ftrapv \-fwrapv \-fbounds\-check \&\-fvisibility\fR .Sh "Options Controlling the Kind of Output" .IX Subsection "Options Controlling the Kind of Output" Compilation can involve up to four stages: preprocessing, compilation proper, assembly and linking, always in that order. \s-1GCC\s0 is capable of preprocessing and compiling several files either into several assembler input files, or into one assembler input file; then each assembler input file produces an object file, and linking combines all the object files (those newly compiled, and those specified as input) into an executable file. .PP For any given input file, the file name suffix determines what kind of compilation is done: .IP "\fIfile\fR\fB.c\fR" 4 .IX Item "file.c" C source code which must be preprocessed. .IP "\fIfile\fR\fB.i\fR" 4 .IX Item "file.i" C source code which should not be preprocessed. .IP "\fIfile\fR\fB.ii\fR" 4 .IX Item "file.ii" \&\*(C+ source code which should not be preprocessed. .IP "\fIfile\fR\fB.h\fR" 4 .IX Item "file.h" C, or \*(C+ header file to be turned into a precompiled header. .IP "\fIfile\fR\fB.cc\fR" 4 .IX Item "file.cc" .PD 0 .IP "\fIfile\fR\fB.cp\fR" 4 .IX Item "file.cp" .IP "\fIfile\fR\fB.cxx\fR" 4 .IX Item "file.cxx" .IP "\fIfile\fR\fB.cpp\fR" 4 .IX Item "file.cpp" .IP "\fIfile\fR\fB.CPP\fR" 4 .IX Item "file.CPP" .IP "\fIfile\fR\fB.c++\fR" 4 .IX Item "file.c++" .IP "\fIfile\fR\fB.C\fR" 4 .IX Item "file.C" .PD \&\*(C+ source code which must be preprocessed. Note that in \fB.cxx\fR, the last two letters must both be literally \fBx\fR. Likewise, \&\fB.C\fR refers to a literal capital C. .IP "\fIfile\fR\fB.hh\fR" 4 .IX Item "file.hh" .PD 0 .IP "\fIfile\fR\fB.H\fR" 4 .IX Item "file.H" .PD \&\*(C+ header file to be turned into a precompiled header. .IP "\fIfile\fR\fB.f\fR" 4 .IX Item "file.f" .PD 0 .IP "\fIfile\fR\fB.for\fR" 4 .IX Item "file.for" .IP "\fIfile\fR\fB.FOR\fR" 4 .IX Item "file.FOR" .PD Fixed form Fortran source code which should not be preprocessed. .IP "\fIfile\fR\fB.F\fR" 4 .IX Item "file.F" .PD 0 .IP "\fIfile\fR\fB.fpp\fR" 4 .IX Item "file.fpp" .IP "\fIfile\fR\fB.FPP\fR" 4 .IX Item "file.FPP" .PD Fixed form Fortran source code which must be preprocessed (with the traditional preprocessor). .IP "\fIfile\fR\fB.f90\fR" 4 .IX Item "file.f90" .PD 0 .IP "\fIfile\fR\fB.f95\fR" 4 .IX Item "file.f95" .PD Free form Fortran source code which should not be preprocessed. .IP "\fIfile\fR\fB.F90\fR" 4 .IX Item "file.F90" .PD 0 .IP "\fIfile\fR\fB.F95\fR" 4 .IX Item "file.F95" .PD Free form Fortran source code which must be preprocessed (with the traditional preprocessor). .IP "\fIfile\fR\fB.ads\fR" 4 .IX Item "file.ads" Ada source code file which contains a library unit declaration (a declaration of a package, subprogram, or generic, or a generic instantiation), or a library unit renaming declaration (a package, generic, or subprogram renaming declaration). Such files are also called \fIspecs\fR. .IP "\fIfile\fR\fB.adb\fR" 4 .IX Item "file.adb" Ada source code file containing a library unit body (a subprogram or package body). Such files are also called \fIbodies\fR. .IP "\fIfile\fR\fB.s\fR" 4 .IX Item "file.s" Assembler code. .IP "\fIfile\fR\fB.S\fR" 4 .IX Item "file.S" Assembler code which must be preprocessed. .IP "\fIother\fR" 4 .IX Item "other" An object file to be fed straight into linking. Any file name with no recognized suffix is treated this way. .PP You can specify the input language explicitly with the \fB\-x\fR option: .IP "\fB\-x\fR \fIlanguage\fR" 4 .IX Item "-x language" Specify explicitly the \fIlanguage\fR for the following input files (rather than letting the compiler choose a default based on the file name suffix). This option applies to all following input files until the next \fB\-x\fR option. Possible values for \fIlanguage\fR are: .Sp .Vb 9 \& c c-header c-cpp-output \& c++ c++-header c++-cpp-output \& assembler assembler-with-cpp \& ada \& f95 f95-cpp-input \& java \& treelang .Ve .IP "\fB\-x none\fR" 4 .IX Item "-x none" Turn off any specification of a language, so that subsequent files are handled according to their file name suffixes (as they are if \fB\-x\fR has not been used at all). .IP "\fB\-pass\-exit\-codes\fR" 4 .IX Item "-pass-exit-codes" Normally the \fBgcc\fR program will exit with the code of 1 if any phase of the compiler returns a non-success return code. If you specify \&\fB\-pass\-exit\-codes\fR, the \fBgcc\fR program will instead return with numerically highest error produced by any phase that returned an error indication. The C, \*(C+, and Fortran frontends return 4, if an internal compiler error is encountered. .PP If you only want some of the stages of compilation, you can use \&\fB\-x\fR (or filename suffixes) to tell \fBgcc\fR where to start, and one of the options \fB\-c\fR, \fB\-S\fR, or \fB\-E\fR to say where \&\fBgcc\fR is to stop. Note that some combinations (for example, \&\fB\-x cpp-output \-E\fR) instruct \fBgcc\fR to do nothing at all. .IP "\fB\-c\fR" 4 .IX Item "-c" Compile or assemble the source files, but do not link. The linking stage simply is not done. The ultimate output is in the form of an object file for each source file. .Sp By default, the object file name for a source file is made by replacing the suffix \fB.c\fR, \fB.i\fR, \fB.s\fR, etc., with \fB.o\fR. .Sp Unrecognized input files, not requiring compilation or assembly, are ignored. .IP "\fB\-S\fR" 4 .IX Item "-S" Stop after the stage of compilation proper; do not assemble. The output is in the form of an assembler code file for each non-assembler input file specified. .Sp By default, the assembler file name for a source file is made by replacing the suffix \fB.c\fR, \fB.i\fR, etc., with \fB.s\fR. .Sp Input files that don't require compilation are ignored. .IP "\fB\-E\fR" 4 .IX Item "-E" Stop after the preprocessing stage; do not run the compiler proper. The output is in the form of preprocessed source code, which is sent to the standard output. .Sp Input files which don't require preprocessing are ignored. .IP "\fB\-o\fR \fIfile\fR" 4 .IX Item "-o file" Place output in file \fIfile\fR. This applies regardless to whatever sort of output is being produced, whether it be an executable file, an object file, an assembler file or preprocessed C code. .Sp If \fB\-o\fR is not specified, the default is to put an executable file in \fIa.out\fR, the object file for \&\fI\fIsource\fI.\fIsuffix\fI\fR in \fI\fIsource\fI.o\fR, its assembler file in \fI\fIsource\fI.s\fR, a precompiled header file in \&\fI\fIsource\fI.\fIsuffix\fI.gch\fR, and all preprocessed C source on standard output. .IP "\fB\-v\fR" 4 .IX Item "-v" Print (on standard error output) the commands executed to run the stages of compilation. Also print the version number of the compiler driver program and of the preprocessor and the compiler proper. .IP "\fB\-###\fR" 4 .IX Item "-###" Like \fB\-v\fR except the commands are not executed and all command arguments are quoted. This is useful for shell scripts to capture the driver-generated command lines. .IP "\fB\-pipe\fR" 4 .IX Item "-pipe" Use pipes rather than temporary files for communication between the various stages of compilation. This fails to work on some systems where the assembler is unable to read from a pipe; but the \s-1GNU\s0 assembler has no trouble. .IP "\fB\-combine\fR" 4 .IX Item "-combine" If you are compiling multiple source files, this option tells the driver to pass all the source files to the compiler at once (for those languages for which the compiler can handle this). This will allow intermodule analysis (\s-1IMA\s0) to be performed by the compiler. Currently the only language for which this is supported is C. If you pass source files for multiple languages to the driver, using this option, the driver will invoke the compiler(s) that support \s-1IMA\s0 once each, passing each compiler all the source files appropriate for it. For those languages that do not support \&\s-1IMA\s0 this option will be ignored, and the compiler will be invoked once for each source file in that language. If you use this option in conjunction with \fB\-save\-temps\fR, the compiler will generate multiple pre-processed files (one for each source file), but only one (combined) \fI.o\fR or \&\fI.s\fR file. .IP "\fB\-\-help\fR" 4 .IX Item "--help" Print (on the standard output) a description of the command line options understood by \fBgcc\fR. If the \fB\-v\fR option is also specified then \fB\-\-help\fR will also be passed on to the various processes invoked by \fBgcc\fR, so that they can display the command line options they accept. If the \fB\-Wextra\fR option is also specified then command line options which have no documentation associated with them will also be displayed. .IP "\fB\-\-target\-help\fR" 4 .IX Item "--target-help" Print (on the standard output) a description of target specific command line options for each tool. .IP "\fB\-\-version\fR" 4 .IX Item "--version" Display the version number and copyrights of the invoked \s-1GCC\s0. .IP "\fB@\fR\fIfile\fR" 4 .IX Item "@file" Read command-line options from \fIfile\fR. The options read are inserted in place of the original @\fIfile\fR option. If \fIfile\fR does not exist, or cannot be read, then the option will be treated literally, and not removed. .Sp Options in \fIfile\fR are separated by whitespace. A whitespace character may be included in an option by surrounding the entire option in either single or double quotes. Any character (including a backslash) may be included by prefixing the character to be included with a backslash. The \fIfile\fR may itself contain additional @\fIfile\fR options; any such options will be processed recursively. .Sh "Compiling \*(C+ Programs" .IX Subsection "Compiling Programs" \&\*(C+ source files conventionally use one of the suffixes \fB.C\fR, \&\fB.cc\fR, \fB.cpp\fR, \fB.CPP\fR, \fB.c++\fR, \fB.cp\fR, or \&\fB.cxx\fR; \*(C+ header files often use \fB.hh\fR or \fB.H\fR; and preprocessed \*(C+ files use the suffix \fB.ii\fR. \s-1GCC\s0 recognizes files with these names and compiles them as \*(C+ programs even if you call the compiler the same way as for compiling C programs (usually with the name \fBgcc\fR). .PP However, the use of \fBgcc\fR does not add the \*(C+ library. \&\fBg++\fR is a program that calls \s-1GCC\s0 and treats \fB.c\fR, \&\fB.h\fR and \fB.i\fR files as \*(C+ source files instead of C source files unless \fB\-x\fR is used, and automatically specifies linking against the \*(C+ library. This program is also useful when precompiling a C header file with a \fB.h\fR extension for use in \*(C+ compilations. On many systems, \fBg++\fR is also installed with the name \fBc++\fR. .PP When you compile \*(C+ programs, you may specify many of the same command-line options that you use for compiling programs in any language; or command-line options meaningful for C and related languages; or options that are meaningful only for \*(C+ programs. .Sh "Options Controlling C Dialect" .IX Subsection "Options Controlling C Dialect" The following options control the dialect of C (or languages derived from C, such as \*(C+) that the compiler accepts: .IP "\fB\-ansi\fR" 4 .IX Item "-ansi" In C mode, support all \s-1ISO\s0 C90 programs. In \*(C+ mode, remove \s-1GNU\s0 extensions that conflict with \s-1ISO\s0 \*(C+. .Sp This turns off certain features of \s-1GCC\s0 that are incompatible with \s-1ISO\s0 C90 (when compiling C code), or of standard \*(C+ (when compiling \*(C+ code), such as the \f(CW\*(C`asm\*(C'\fR and \f(CW\*(C`typeof\*(C'\fR keywords, and predefined macros such as \f(CW\*(C`unix\*(C'\fR and \f(CW\*(C`vax\*(C'\fR that identify the type of system you are using. It also enables the undesirable and rarely used \s-1ISO\s0 trigraph feature. For the C compiler, it disables recognition of \*(C+ style \fB//\fR comments as well as the \f(CW\*(C`inline\*(C'\fR keyword. .Sp The alternate keywords \f(CW\*(C`_\|_asm_\|_\*(C'\fR, \f(CW\*(C`_\|_extension_\|_\*(C'\fR, \&\f(CW\*(C`_\|_inline_\|_\*(C'\fR and \f(CW\*(C`_\|_typeof_\|_\*(C'\fR continue to work despite \&\fB\-ansi\fR. You would not want to use them in an \s-1ISO\s0 C program, of course, but it is useful to put them in header files that might be included in compilations done with \fB\-ansi\fR. Alternate predefined macros such as \f(CW\*(C`_\|_unix_\|_\*(C'\fR and \f(CW\*(C`_\|_vax_\|_\*(C'\fR are also available, with or without \fB\-ansi\fR. .Sp The \fB\-ansi\fR option does not cause non-ISO programs to be rejected gratuitously. For that, \fB\-pedantic\fR is required in addition to \fB\-ansi\fR. .Sp The macro \f(CW\*(C`_\|_STRICT_ANSI_\|_\*(C'\fR is predefined when the \fB\-ansi\fR option is used. Some header files may notice this macro and refrain from declaring certain functions or defining certain macros that the \&\s-1ISO\s0 standard doesn't call for; this is to avoid interfering with any programs that might use these names for other things. .Sp Functions which would normally be built in but do not have semantics defined by \s-1ISO\s0 C (such as \f(CW\*(C`alloca\*(C'\fR and \f(CW\*(C`ffs\*(C'\fR) are not built-in functions with \fB\-ansi\fR is used. .IP "\fB\-std=\fR" 4 .IX Item "-std=" Determine the language standard. This option is currently only supported when compiling C or \*(C+. A value for this option must be provided; possible values are .RS 4 .IP "\fBc89\fR" 4 .IX Item "c89" .PD 0 .IP "\fBiso9899:1990\fR" 4 .IX Item "iso9899:1990" .PD \&\s-1ISO\s0 C90 (same as \fB\-ansi\fR). .IP "\fBiso9899:199409\fR" 4 .IX Item "iso9899:199409" \&\s-1ISO\s0 C90 as modified in amendment 1. .IP "\fBc99\fR" 4 .IX Item "c99" .PD 0 .IP "\fBc9x\fR" 4 .IX Item "c9x" .IP "\fBiso9899:1999\fR" 4 .IX Item "iso9899:1999" .IP "\fBiso9899:199x\fR" 4 .IX Item "iso9899:199x" .PD \&\s-1ISO\s0 C99. Note that this standard is not yet fully supported; see <\fBhttp://gcc.gnu.org/gcc\-4.2/c99status.html\fR> for more information. The names \fBc9x\fR and \fBiso9899:199x\fR are deprecated. .IP "\fBgnu89\fR" 4 .IX Item "gnu89" Default, \s-1ISO\s0 C90 plus \s-1GNU\s0 extensions (including some C99 features). .IP "\fBgnu99\fR" 4 .IX Item "gnu99" .PD 0 .IP "\fBgnu9x\fR" 4 .IX Item "gnu9x" .PD \&\s-1ISO\s0 C99 plus \s-1GNU\s0 extensions. When \s-1ISO\s0 C99 is fully implemented in \s-1GCC\s0, this will become the default. The name \fBgnu9x\fR is deprecated. .IP "\fBc++98\fR" 4 .IX Item "c++98" The 1998 \s-1ISO\s0 \*(C+ standard plus amendments. .IP "\fBgnu++98\fR" 4 .IX Item "gnu++98" The same as \fB\-std=c++98\fR plus \s-1GNU\s0 extensions. This is the default for \*(C+ code. .RE .RS 4 .Sp Even when this option is not specified, you can still use some of the features of newer standards in so far as they do not conflict with previous C standards. For example, you may use \f(CW\*(C`_\|_restrict_\|_\*(C'\fR even when \fB\-std=c99\fR is not specified. .Sp The \fB\-std\fR options specifying some version of \s-1ISO\s0 C have the same effects as \fB\-ansi\fR, except that features that were not in \s-1ISO\s0 C90 but are in the specified version (for example, \fB//\fR comments and the \f(CW\*(C`inline\*(C'\fR keyword in \s-1ISO\s0 C99) are not disabled. .RE .IP "\fB\-fgnu89\-inline\fR" 4 .IX Item "-fgnu89-inline" The option \fB\-fgnu89\-inline\fR tells \s-1GCC\s0 to use the traditional \&\s-1GNU\s0 semantics for \f(CW\*(C`inline\*(C'\fR functions when in C99 mode. Using this option is roughly equivalent to adding the \f(CW\*(C`gnu_inline\*(C'\fR function attribute to all inline functions. .Sp This option is accepted by \s-1GCC\s0 versions 4.1.3 and up. In \s-1GCC\s0 versions prior to 4.3, C99 inline semantics are not supported, and thus this option is effectively assumed to be present regardless of whether or not it is specified; the only effect of specifying it explicitly is to disable warnings about using inline functions in C99 mode. Likewise, the option \fB\-fno\-gnu89\-inline\fR is not supported in versions of \&\s-1GCC\s0 before 4.3. It will be supported only in C99 or gnu99 mode, not in C89 or gnu89 mode. .Sp The preprocesor macros \f(CW\*(C`_\|_GNUC_GNU_INLINE_\|_\*(C'\fR and \&\f(CW\*(C`_\|_GNUC_STDC_INLINE_\|_\*(C'\fR may be used to check which semantics are in effect for \f(CW\*(C`inline\*(C'\fR functions. .IP "\fB\-aux\-info\fR \fIfilename\fR" 4 .IX Item "-aux-info filename" Output to the given filename prototyped declarations for all functions declared and/or defined in a translation unit, including those in header files. This option is silently ignored in any language other than C. .Sp Besides declarations, the file indicates, in comments, the origin of each declaration (source file and line), whether the declaration was implicit, prototyped or unprototyped (\fBI\fR, \fBN\fR for new or \&\fBO\fR for old, respectively, in the first character after the line number and the colon), and whether it came from a declaration or a definition (\fBC\fR or \fBF\fR, respectively, in the following character). In the case of function definitions, a K&R\-style list of arguments followed by their declarations is also provided, inside comments, after the declaration. .IP "\fB\-fno\-asm\fR" 4 .IX Item "-fno-asm" Do not recognize \f(CW\*(C`asm\*(C'\fR, \f(CW\*(C`inline\*(C'\fR or \f(CW\*(C`typeof\*(C'\fR as a keyword, so that code can use these words as identifiers. You can use the keywords \f(CW\*(C`_\|_asm_\|_\*(C'\fR, \f(CW\*(C`_\|_inline_\|_\*(C'\fR and \f(CW\*(C`_\|_typeof_\|_\*(C'\fR instead. \fB\-ansi\fR implies \fB\-fno\-asm\fR. .Sp In \*(C+, this switch only affects the \f(CW\*(C`typeof\*(C'\fR keyword, since \&\f(CW\*(C`asm\*(C'\fR and \f(CW\*(C`inline\*(C'\fR are standard keywords. You may want to use the \fB\-fno\-gnu\-keywords\fR flag instead, which has the same effect. In C99 mode (\fB\-std=c99\fR or \fB\-std=gnu99\fR), this switch only affects the \f(CW\*(C`asm\*(C'\fR and \f(CW\*(C`typeof\*(C'\fR keywords, since \&\f(CW\*(C`inline\*(C'\fR is a standard keyword in \s-1ISO\s0 C99. .IP "\fB\-fno\-builtin\fR" 4 .IX Item "-fno-builtin" .PD 0 .IP "\fB\-fno\-builtin\-\fR\fIfunction\fR" 4 .IX Item "-fno-builtin-function" .PD Don't recognize built-in functions that do not begin with \&\fB_\|_builtin_\fR as prefix. .Sp \&\s-1GCC\s0 normally generates special code to handle certain built-in functions more efficiently; for instance, calls to \f(CW\*(C`alloca\*(C'\fR may become single instructions that adjust the stack directly, and calls to \f(CW\*(C`memcpy\*(C'\fR may become inline copy loops. The resulting code is often both smaller and faster, but since the function calls no longer appear as such, you cannot set a breakpoint on those calls, nor can you change the behavior of the functions by linking with a different library. In addition, when a function is recognized as a built-in function, \s-1GCC\s0 may use information about that function to warn about problems with calls to that function, or to generate more efficient code, even if the resulting code still contains calls to that function. For example, warnings are given with \fB\-Wformat\fR for bad calls to \&\f(CW\*(C`printf\*(C'\fR, when \f(CW\*(C`printf\*(C'\fR is built in, and \f(CW\*(C`strlen\*(C'\fR is known not to modify global memory. .Sp With the \fB\-fno\-builtin\-\fR\fIfunction\fR option only the built-in function \fIfunction\fR is disabled. \fIfunction\fR must not begin with \fB_\|_builtin_\fR. If a function is named this is not built-in in this version of \s-1GCC\s0, this option is ignored. There is no corresponding \&\fB\-fbuiltin\-\fR\fIfunction\fR option; if you wish to enable built-in functions selectively when using \fB\-fno\-builtin\fR or \&\fB\-ffreestanding\fR, you may define macros such as: .Sp .Vb 2 \& #define abs(n) __builtin_abs ((n)) \& #define strcpy(d, s) __builtin_strcpy ((d), (s)) .Ve .IP "\fB\-fhosted\fR" 4 .IX Item "-fhosted" Assert that compilation takes place in a hosted environment. This implies \&\fB\-fbuiltin\fR. A hosted environment is one in which the entire standard library is available, and in which \f(CW\*(C`main\*(C'\fR has a return type of \f(CW\*(C`int\*(C'\fR. Examples are nearly everything except a kernel. This is equivalent to \fB\-fno\-freestanding\fR. .IP "\fB\-ffreestanding\fR" 4 .IX Item "-ffreestanding" Assert that compilation takes place in a freestanding environment. This implies \fB\-fno\-builtin\fR. A freestanding environment is one in which the standard library may not exist, and program startup may not necessarily be at \f(CW\*(C`main\*(C'\fR. The most obvious example is an \s-1OS\s0 kernel. This is equivalent to \fB\-fno\-hosted\fR. .IP "\fB\-fopenmp\fR" 4 .IX Item "-fopenmp" Enable handling of OpenMP directives \f(CW\*(C`#pragma omp\*(C'\fR in C/\*(C+ and \&\f(CW\*(C`!$omp\*(C'\fR in Fortran. When \fB\-fopenmp\fR is specified, the compiler generates parallel code according to the OpenMP Application Program Interface v2.5 <\fBhttp://www.openmp.org/\fR>. .IP "\fB\-fms\-extensions\fR" 4 .IX Item "-fms-extensions" Accept some non-standard constructs used in Microsoft header files. .Sp Some cases of unnamed fields in structures and unions are only accepted with this option. .IP "\fB\-trigraphs\fR" 4 .IX Item "-trigraphs" Support \s-1ISO\s0 C trigraphs. The \fB\-ansi\fR option (and \fB\-std\fR options for strict \s-1ISO\s0 C conformance) implies \fB\-trigraphs\fR. .IP "\fB\-no\-integrated\-cpp\fR" 4 .IX Item "-no-integrated-cpp" Performs a compilation in two passes: preprocessing and compiling. This option allows a user supplied \*(L"cc1\*(R", \*(L"cc1plus\*(R", or \*(L"cc1obj\*(R" via the \&\fB\-B\fR option. The user supplied compilation step can then add in an additional preprocessing step after normal preprocessing but before compiling. The default is to use the integrated cpp (internal cpp) .Sp The semantics of this option will change if \*(L"cc1\*(R", \*(L"cc1plus\*(R", and \&\*(L"cc1obj\*(R" are merged. .IP "\fB\-traditional\fR" 4 .IX Item "-traditional" .PD 0 .IP "\fB\-traditional\-cpp\fR" 4 .IX Item "-traditional-cpp" .PD Formerly, these options caused \s-1GCC\s0 to attempt to emulate a pre-standard C compiler. They are now only supported with the \fB\-E\fR switch. The preprocessor continues to support a pre-standard mode. See the \s-1GNU\s0 \&\s-1CPP\s0 manual for details. .IP "\fB\-fcond\-mismatch\fR" 4 .IX Item "-fcond-mismatch" Allow conditional expressions with mismatched types in the second and third arguments. The value of such an expression is void. This option is not supported for \*(C+. .IP "\fB\-funsigned\-char\fR" 4 .IX Item "-funsigned-char" Let the type \f(CW\*(C`char\*(C'\fR be unsigned, like \f(CW\*(C`unsigned char\*(C'\fR. .Sp Each kind of machine has a default for what \f(CW\*(C`char\*(C'\fR should be. It is either like \f(CW\*(C`unsigned char\*(C'\fR by default or like \&\f(CW\*(C`signed char\*(C'\fR by default. .Sp Ideally, a portable program should always use \f(CW\*(C`signed char\*(C'\fR or \&\f(CW\*(C`unsigned char\*(C'\fR when it depends on the signedness of an object. But many programs have been written to use plain \f(CW\*(C`char\*(C'\fR and expect it to be signed, or expect it to be unsigned, depending on the machines they were written for. This option, and its inverse, let you make such a program work with the opposite default. .Sp The type \f(CW\*(C`char\*(C'\fR is always a distinct type from each of \&\f(CW\*(C`signed char\*(C'\fR or \f(CW\*(C`unsigned char\*(C'\fR, even though its behavior is always just like one of those two. .IP "\fB\-fsigned\-char\fR" 4 .IX Item "-fsigned-char" Let the type \f(CW\*(C`char\*(C'\fR be signed, like \f(CW\*(C`signed char\*(C'\fR. .Sp Note that this is equivalent to \fB\-fno\-unsigned\-char\fR, which is the negative form of \fB\-funsigned\-char\fR. Likewise, the option \&\fB\-fno\-signed\-char\fR is equivalent to \fB\-funsigned\-char\fR. .IP "\fB\-fsigned\-bitfields\fR" 4 .IX Item "-fsigned-bitfields" .PD 0 .IP "\fB\-funsigned\-bitfields\fR" 4 .IX Item "-funsigned-bitfields" .IP "\fB\-fno\-signed\-bitfields\fR" 4 .IX Item "-fno-signed-bitfields" .IP "\fB\-fno\-unsigned\-bitfields\fR" 4 .IX Item "-fno-unsigned-bitfields" .PD These options control whether a bit-field is signed or unsigned, when the declaration does not use either \f(CW\*(C`signed\*(C'\fR or \f(CW\*(C`unsigned\*(C'\fR. By default, such a bit-field is signed, because this is consistent: the basic integer types such as \f(CW\*(C`int\*(C'\fR are signed types. .Sh "Options Controlling \*(C+ Dialect" .IX Subsection "Options Controlling Dialect" This section describes the command-line options that are only meaningful for \*(C+ programs; but you can also use most of the \s-1GNU\s0 compiler options regardless of what language your program is in. For example, you might compile a file \f(CW\*(C`firstClass.C\*(C'\fR like this: .PP .Vb 1 \& g++ -g -frepo -O -c firstClass.C .Ve .PP In this example, only \fB\-frepo\fR is an option meant only for \*(C+ programs; you can use the other options with any language supported by \s-1GCC\s0. .PP Here is a list of options that are \fIonly\fR for compiling \*(C+ programs: .IP "\fB\-fabi\-version=\fR\fIn\fR" 4 .IX Item "-fabi-version=n" Use version \fIn\fR of the \*(C+ \s-1ABI\s0. Version 2 is the version of the \&\*(C+ \s-1ABI\s0 that first appeared in G++ 3.4. Version 1 is the version of the \*(C+ \s-1ABI\s0 that first appeared in G++ 3.2. Version 0 will always be the version that conforms most closely to the \*(C+ \s-1ABI\s0 specification. Therefore, the \s-1ABI\s0 obtained using version 0 will change as \s-1ABI\s0 bugs are fixed. .Sp The default is version 2. .IP "\fB\-fno\-access\-control\fR" 4 .IX Item "-fno-access-control" Turn off all access checking. This switch is mainly useful for working around bugs in the access control code. .IP "\fB\-fcheck\-new\fR" 4 .IX Item "-fcheck-new" Check that the pointer returned by \f(CW\*(C`operator new\*(C'\fR is non-null before attempting to modify the storage allocated. This check is normally unnecessary because the \*(C+ standard specifies that \&\f(CW\*(C`operator new\*(C'\fR will only return \f(CW0\fR if it is declared \&\fB\f(BIthrow()\fB\fR, in which case the compiler will always check the return value even without this option. In all other cases, when \&\f(CW\*(C`operator new\*(C'\fR has a non-empty exception specification, memory exhaustion is signalled by throwing \f(CW\*(C`std::bad_alloc\*(C'\fR. See also \&\fBnew (nothrow)\fR. .IP "\fB\-fconserve\-space\fR" 4 .IX Item "-fconserve-space" Put uninitialized or runtime-initialized global variables into the common segment, as C does. This saves space in the executable at the cost of not diagnosing duplicate definitions. If you compile with this flag and your program mysteriously crashes after \f(CW\*(C`main()\*(C'\fR has completed, you may have an object that is being destroyed twice because two definitions were merged. .Sp This option is no longer useful on most targets, now that support has been added for putting variables into \s-1BSS\s0 without making them common. .IP "\fB\-ffriend\-injection\fR" 4 .IX Item "-ffriend-injection" Inject friend functions into the enclosing namespace, so that they are visible outside the scope of the class in which they are declared. Friend functions were documented to work this way in the old Annotated \&\*(C+ Reference Manual, and versions of G++ before 4.1 always worked that way. However, in \s-1ISO\s0 \*(C+ a friend function which is not declared in an enclosing scope can only be found using argument dependent lookup. This option causes friends to be injected as they were in earlier releases. .Sp This option is for compatibility, and may be removed in a future release of G++. .IP "\fB\-fno\-elide\-constructors\fR" 4 .IX Item "-fno-elide-constructors" The \*(C+ standard allows an implementation to omit creating a temporary which is only used to initialize another object of the same type. Specifying this option disables that optimization, and forces G++ to call the copy constructor in all cases. .IP "\fB\-fno\-enforce\-eh\-specs\fR" 4 .IX Item "-fno-enforce-eh-specs" Don't generate code to check for violation of exception specifications at runtime. This option violates the \*(C+ standard, but may be useful for reducing code size in production builds, much like defining \&\fB\s-1NDEBUG\s0\fR. This does not give user code permission to throw exceptions in violation of the exception specifications; the compiler will still optimize based on the specifications, so throwing an unexpected exception will result in undefined behavior. .IP "\fB\-ffor\-scope\fR" 4 .IX Item "-ffor-scope" .PD 0 .IP "\fB\-fno\-for\-scope\fR" 4 .IX Item "-fno-for-scope" .PD If \fB\-ffor\-scope\fR is specified, the scope of variables declared in a \fIfor-init-statement\fR is limited to the \fBfor\fR loop itself, as specified by the \*(C+ standard. If \fB\-fno\-for\-scope\fR is specified, the scope of variables declared in a \fIfor-init-statement\fR extends to the end of the enclosing scope, as was the case in old versions of G++, and other (traditional) implementations of \*(C+. .Sp The default if neither flag is given to follow the standard, but to allow and give a warning for old-style code that would otherwise be invalid, or have different behavior. .IP "\fB\-fno\-gnu\-keywords\fR" 4 .IX Item "-fno-gnu-keywords" Do not recognize \f(CW\*(C`typeof\*(C'\fR as a keyword, so that code can use this word as an identifier. You can use the keyword \f(CW\*(C`_\|_typeof_\|_\*(C'\fR instead. \&\fB\-ansi\fR implies \fB\-fno\-gnu\-keywords\fR. .IP "\fB\-fno\-implicit\-templates\fR" 4 .IX Item "-fno-implicit-templates" Never emit code for non-inline templates which are instantiated implicitly (i.e. by use); only emit code for explicit instantiations. .IP "\fB\-fno\-implicit\-inline\-templates\fR" 4 .IX Item "-fno-implicit-inline-templates" Don't emit code for implicit instantiations of inline templates, either. The default is to handle inlines differently so that compiles with and without optimization will need the same set of explicit instantiations. .IP "\fB\-fno\-implement\-inlines\fR" 4 .IX Item "-fno-implement-inlines" To save space, do not emit out-of-line copies of inline functions controlled by \fB#pragma implementation\fR. This will cause linker errors if these functions are not inlined everywhere they are called. .IP "\fB\-fms\-extensions\fR" 4 .IX Item "-fms-extensions" Disable pedantic warnings about constructs used in \s-1MFC\s0, such as implicit int and getting a pointer to member function via non-standard syntax. .IP "\fB\-fno\-nonansi\-builtins\fR" 4 .IX Item "-fno-nonansi-builtins" Disable built-in declarations of functions that are not mandated by \&\s-1ANSI/ISO\s0 C. These include \f(CW\*(C`ffs\*(C'\fR, \f(CW\*(C`alloca\*(C'\fR, \f(CW\*(C`_exit\*(C'\fR, \&\f(CW\*(C`index\*(C'\fR, \f(CW\*(C`bzero\*(C'\fR, \f(CW\*(C`conjf\*(C'\fR, and other related functions. .IP "\fB\-fno\-operator\-names\fR" 4 .IX Item "-fno-operator-names" Do not treat the operator name keywords \f(CW\*(C`and\*(C'\fR, \f(CW\*(C`bitand\*(C'\fR, \&\f(CW\*(C`bitor\*(C'\fR, \f(CW\*(C`compl\*(C'\fR, \f(CW\*(C`not\*(C'\fR, \f(CW\*(C`or\*(C'\fR and \f(CW\*(C`xor\*(C'\fR as synonyms as keywords. .IP "\fB\-fno\-optional\-diags\fR" 4 .IX Item "-fno-optional-diags" Disable diagnostics that the standard says a compiler does not need to issue. Currently, the only such diagnostic issued by G++ is the one for a name having multiple meanings within a class. .IP "\fB\-fpermissive\fR" 4 .IX Item "-fpermissive" Downgrade some diagnostics about nonconformant code from errors to warnings. Thus, using \fB\-fpermissive\fR will allow some nonconforming code to compile. .IP "\fB\-frepo\fR" 4 .IX Item "-frepo" Enable automatic template instantiation at link time. This option also implies \fB\-fno\-implicit\-templates\fR. .IP "\fB\-fno\-rtti\fR" 4 .IX Item "-fno-rtti" Disable generation of information about every class with virtual functions for use by the \*(C+ runtime type identification features (\fBdynamic_cast\fR and \fBtypeid\fR). If you don't use those parts of the language, you can save some space by using this flag. Note that exception handling uses the same information, but it will generate it as needed. The \fBdynamic_cast\fR operator can still be used for casts that do not require runtime type information, i.e. casts to \f(CW\*(C`void *\*(C'\fR or to unambiguous base classes. .IP "\fB\-fstats\fR" 4 .IX Item "-fstats" Emit statistics about front-end processing at the end of the compilation. This information is generally only useful to the G++ development team. .IP "\fB\-ftemplate\-depth\-\fR\fIn\fR" 4 .IX Item "-ftemplate-depth-n" Set the maximum instantiation depth for template classes to \fIn\fR. A limit on the template instantiation depth is needed to detect endless recursions during template class instantiation. \s-1ANSI/ISO\s0 \*(C+ conforming programs must not rely on a maximum depth greater than 17. .IP "\fB\-fno\-threadsafe\-statics\fR" 4 .IX Item "-fno-threadsafe-statics" Do not emit the extra code to use the routines specified in the \*(C+ \&\s-1ABI\s0 for thread-safe initialization of local statics. You can use this option to reduce code size slightly in code that doesn't need to be thread\-safe. .IP "\fB\-fuse\-cxa\-atexit\fR" 4 .IX Item "-fuse-cxa-atexit" Register destructors for objects with static storage duration with the \&\f(CW\*(C`_\|_cxa_atexit\*(C'\fR function rather than the \f(CW\*(C`atexit\*(C'\fR function. This option is required for fully standards-compliant handling of static destructors, but will only work if your C library supports \&\f(CW\*(C`_\|_cxa_atexit\*(C'\fR. .IP "\fB\-fno\-use\-cxa\-get\-exception\-ptr\fR" 4 .IX Item "-fno-use-cxa-get-exception-ptr" Don't use the \f(CW\*(C`_\|_cxa_get_exception_ptr\*(C'\fR runtime routine. This will cause \f(CW\*(C`std::uncaught_exception\*(C'\fR to be incorrect, but is necessary if the runtime routine is not available. .IP "\fB\-fvisibility\-inlines\-hidden\fR" 4 .IX Item "-fvisibility-inlines-hidden" This switch declares that the user does not attempt to compare pointers to inline methods where the addresses of the two functions were taken in different shared objects. .Sp The effect of this is that \s-1GCC\s0 may, effectively, mark inline methods with \&\f(CW\*(C`_\|_attribute_\|_ ((visibility ("hidden")))\*(C'\fR so that they do not appear in the export table of a \s-1DSO\s0 and do not require a \s-1PLT\s0 indirection when used within the \s-1DSO\s0. Enabling this option can have a dramatic effect on load and link times of a \s-1DSO\s0 as it massively reduces the size of the dynamic export table when the library makes heavy use of templates. .Sp The behaviour of this switch is not quite the same as marking the methods as hidden directly, because it does not affect static variables local to the function or cause the compiler to deduce that the function is defined in only one shared object. .Sp You may mark a method as having a visibility explicitly to negate the effect of the switch for that method. For example, if you do want to compare pointers to a particular inline method, you might mark it as having default visibility. Marking the enclosing class with explicit visibility will have no effect. .Sp Explicitly instantiated inline methods are unaffected by this option as their linkage might otherwise cross a shared library boundary. .IP "\fB\-fno\-weak\fR" 4 .IX Item "-fno-weak" Do not use weak symbol support, even if it is provided by the linker. By default, G++ will use weak symbols if they are available. This option exists only for testing, and should not be used by end\-users; it will result in inferior code and has no benefits. This option may be removed in a future release of G++. .IP "\fB\-nostdinc++\fR" 4 .IX Item "-nostdinc++" Do not search for header files in the standard directories specific to \&\*(C+, but do still search the other standard directories. (This option is used when building the \*(C+ library.) .PP In addition, these optimization, warning, and code generation options have meanings only for \*(C+ programs: .IP "\fB\-fno\-default\-inline\fR" 4 .IX Item "-fno-default-inline" Do not assume \fBinline\fR for functions defined inside a class scope. Note that these functions will have linkage like inline functions; they just won't be inlined by default. .IP "\fB\-Wabi\fR (\*(C+ only)" 4 .IX Item "-Wabi ( only)" Warn when G++ generates code that is probably not compatible with the vendor-neutral \*(C+ \s-1ABI\s0. Although an effort has been made to warn about all such cases, there are probably some cases that are not warned about, even though G++ is generating incompatible code. There may also be cases where warnings are emitted even though the code that is generated will be compatible. .Sp You should rewrite your code to avoid these warnings if you are concerned about the fact that code generated by G++ may not be binary compatible with code generated by other compilers. .Sp The known incompatibilities at this point include: .RS 4 .IP "*" 4 Incorrect handling of tail-padding for bit\-fields. G++ may attempt to pack data into the same byte as a base class. For example: .Sp .Vb 2 \& struct A { virtual void f(); int f1 : 1; }; \& struct B : public A { int f2 : 1; }; .Ve .Sp In this case, G++ will place \f(CW\*(C`B::f2\*(C'\fR into the same byte as\f(CW\*(C`A::f1\*(C'\fR; other compilers will not. You can avoid this problem by explicitly padding \f(CW\*(C`A\*(C'\fR so that its size is a multiple of the byte size on your platform; that will cause G++ and other compilers to layout \f(CW\*(C`B\*(C'\fR identically. .IP "*" 4 Incorrect handling of tail-padding for virtual bases. G++ does not use tail padding when laying out virtual bases. For example: .Sp .Vb 3 \& struct A { virtual void f(); char c1; }; \& struct B { B(); char c2; }; \& struct C : public A, public virtual B {}; .Ve .Sp In this case, G++ will not place \f(CW\*(C`B\*(C'\fR into the tail-padding for \&\f(CW\*(C`A\*(C'\fR; other compilers will. You can avoid this problem by explicitly padding \f(CW\*(C`A\*(C'\fR so that its size is a multiple of its alignment (ignoring virtual base classes); that will cause G++ and other compilers to layout \f(CW\*(C`C\*(C'\fR identically. .IP "*" 4 Incorrect handling of bit-fields with declared widths greater than that of their underlying types, when the bit-fields appear in a union. For example: .Sp .Vb 1 \& union U { int i : 4096; }; .Ve .Sp Assuming that an \f(CW\*(C`int\*(C'\fR does not have 4096 bits, G++ will make the union too small by the number of bits in an \f(CW\*(C`int\*(C'\fR. .IP "*" 4 Empty classes can be placed at incorrect offsets. For example: .Sp .Vb 1 \& struct A {}; .Ve .Sp .Vb 4 \& struct B { \& A a; \& virtual void f (); \& }; .Ve .Sp .Vb 1 \& struct C : public B, public A {}; .Ve .Sp G++ will place the \f(CW\*(C`A\*(C'\fR base class of \f(CW\*(C`C\*(C'\fR at a nonzero offset; it should be placed at offset zero. G++ mistakenly believes that the \&\f(CW\*(C`A\*(C'\fR data member of \f(CW\*(C`B\*(C'\fR is already at offset zero. .IP "*" 4 Names of template functions whose types involve \f(CW\*(C`typename\*(C'\fR or template template parameters can be mangled incorrectly. .Sp .Vb 2 \& template \& void f(typename Q::X) {} .Ve .Sp .Vb 2 \& template