2 Copyright 1988-2022 Free Software Foundation, Inc.
3 This is part of the GCC manual.
4 For copying conditions, see the copyright.rst file.
6 .. index:: dialect options, language dialect options, options, dialect
10 Options Controlling C Dialect
11 *****************************
13 The following options control the dialect of C (or languages derived
14 from C, such as C++, Objective-C and Objective-C++) that the compiler
17 .. index:: ANSI support, ISO support
21 In C mode, this is equivalent to :option:`-std=c90`. In C++ mode, it is
22 equivalent to :option:`-std=c++98`.
24 This turns off certain features of GCC that are incompatible with ISO
25 C90 (when compiling C code), or of standard C++ (when compiling C++ code),
26 such as the ``asm`` and ``typeof`` keywords, and
27 predefined macros such as ``unix`` and ``vax`` that identify the
28 type of system you are using. It also enables the undesirable and
29 rarely used ISO trigraph feature. For the C compiler,
30 it disables recognition of C++ style :samp:`//` comments as well as
31 the ``inline`` keyword.
33 The alternate keywords ``__asm__``, ``__extension__``,
34 ``__inline__`` and ``__typeof__`` continue to work despite
35 :option:`-ansi`. You would not want to use them in an ISO C program, of
36 course, but it is useful to put them in header files that might be included
37 in compilations done with :option:`-ansi`. Alternate predefined macros
38 such as ``__unix__`` and ``__vax__`` are also available, with or
39 without :option:`-ansi`.
41 The :option:`-ansi` option does not cause non-ISO programs to be
42 rejected gratuitously. For that, :option:`-Wpedantic` is required in
43 addition to :option:`-ansi`. See :ref:`warning-options`.
45 The macro ``__STRICT_ANSI__`` is predefined when the :option:`-ansi`
46 option is used. Some header files may notice this macro and refrain
47 from declaring certain functions or defining certain macros that the
48 ISO standard doesn't call for; this is to avoid interfering with any
49 programs that might use these names for other things.
51 Functions that are normally built in but do not have semantics
52 defined by ISO C (such as ``alloca`` and ``ffs``) are not built-in
53 functions when :option:`-ansi` is used. See :ref:`other-builtins`, for details of the functions
58 Determine the language standard. See :ref:`standards`, for details of these standard versions. This option
59 is currently only supported when compiling C or C++.
61 The compiler can accept several base standards, such as :samp:`c90` or
62 :samp:`c++98`, and GNU dialects of those standards, such as
63 :samp:`gnu90` or :samp:`gnu++98`. When a base standard is specified, the
64 compiler accepts all programs following that standard plus those
65 using GNU extensions that do not contradict it. For example,
66 :option:`-std=c90` turns off certain features of GCC that are
67 incompatible with ISO C90, such as the ``asm`` and ``typeof``
68 keywords, but not other GNU extensions that do not have a meaning in
69 ISO C90, such as omitting the middle term of a ``?:``
70 expression. On the other hand, when a GNU dialect of a standard is
71 specified, all features supported by the compiler are enabled, even when
72 those features change the meaning of the base standard. As a result, some
73 strict-conforming programs may be rejected. The particular standard
74 is used by :option:`-Wpedantic` to identify which features are GNU
75 extensions given that version of the standard. For example
76 :option:`-std=gnu90 -Wpedantic` warns about C++ style :samp:`//`
77 comments, while :option:`-std=gnu99 -Wpedantic` does not.
79 A value for this option must be provided; possible values are
81 :samp:`c90` :samp:`c89` :samp:`iso9899:1990`
82 Support all ISO C90 programs (certain GNU extensions that conflict
83 with ISO C90 are disabled). Same as :option:`-ansi` for C code.
85 :samp:`iso9899:199409`
86 ISO C90 as modified in amendment 1.
88 :samp:`c99` :samp:`c9x` :samp:`iso9899:1999` :samp:`iso9899:199x`
89 ISO C99. This standard is substantially completely supported, modulo
90 bugs and floating-point issues
91 (mainly but not entirely relating to optional C99 features from
93 https://gcc.gnu.org/c99status.html for more information. The
94 names :samp:`c9x` and :samp:`iso9899:199x` are deprecated.
96 :samp:`c11` :samp:`c1x` :samp:`iso9899:2011`
97 ISO C11, the 2011 revision of the ISO C standard. This standard is
98 substantially completely supported, modulo bugs, floating-point issues
99 (mainly but not entirely relating to optional C11 features from
100 Annexes F and G) and the optional Annexes K (Bounds-checking
101 interfaces) and L (Analyzability). The name :samp:`c1x` is deprecated.
103 :samp:`c17` :samp:`c18` :samp:`iso9899:2017` :samp:`iso9899:2018`
104 ISO C17, the 2017 revision of the ISO C standard
105 (published in 2018). This standard is
106 same as C11 except for corrections of defects (all of which are also
107 applied with :option:`-std=c11`) and a new value of
108 ``__STDC_VERSION__``, and so is supported to the same extent as C11.
111 The next version of the ISO C standard, still under development. The
112 support for this version is experimental and incomplete.
114 :samp:`gnu90` :samp:`gnu89`
115 GNU dialect of ISO C90 (including some C99 features).
117 :samp:`gnu99` :samp:`gnu9x`
118 GNU dialect of ISO C99. The name :samp:`gnu9x` is deprecated.
120 :samp:`gnu11` :samp:`gnu1x`
121 GNU dialect of ISO C11.
122 The name :samp:`gnu1x` is deprecated.
124 :samp:`gnu17` :samp:`gnu18`
125 GNU dialect of ISO C17. This is the default for C code.
128 The next version of the ISO C standard, still under development, plus
129 GNU extensions. The support for this version is experimental and
132 :samp:`c++98` :samp:`c++03`
133 The 1998 ISO C++ standard plus the 2003 technical corrigendum and some
134 additional defect reports. Same as :option:`-ansi` for C++ code.
136 :samp:`gnu++98` :samp:`gnu++03`
137 GNU dialect of :option:`-std=c++98`.
139 :samp:`c++11` :samp:`c++0x`
140 The 2011 ISO C++ standard plus amendments.
141 The name :samp:`c++0x` is deprecated.
143 :samp:`gnu++11` :samp:`gnu++0x`
144 GNU dialect of :option:`-std=c++11`.
145 The name :samp:`gnu++0x` is deprecated.
147 :samp:`c++14` :samp:`c++1y`
148 The 2014 ISO C++ standard plus amendments.
149 The name :samp:`c++1y` is deprecated.
151 :samp:`gnu++14` :samp:`gnu++1y`
152 GNU dialect of :option:`-std=c++14`.
153 The name :samp:`gnu++1y` is deprecated.
155 :samp:`c++17` :samp:`c++1z`
156 The 2017 ISO C++ standard plus amendments.
157 The name :samp:`c++1z` is deprecated.
159 :samp:`gnu++17` :samp:`gnu++1z`
160 GNU dialect of :option:`-std=c++17`.
161 This is the default for C++ code.
162 The name :samp:`gnu++1z` is deprecated.
164 :samp:`c++20` :samp:`c++2a`
165 The 2020 ISO C++ standard plus amendments.
166 Support is experimental, and could change in incompatible ways in
168 The name :samp:`c++2a` is deprecated.
170 :samp:`gnu++20` :samp:`gnu++2a`
171 GNU dialect of :option:`-std=c++20`.
172 Support is experimental, and could change in incompatible ways in
174 The name :samp:`gnu++2a` is deprecated.
176 :samp:`c++2b` :samp:`c++23`
177 The next revision of the ISO C++ standard, planned for
178 2023. Support is highly experimental, and will almost certainly
179 change in incompatible ways in future releases.
181 :samp:`gnu++2b` :samp:`gnu++23`
182 GNU dialect of :option:`-std=c++2b`. Support is highly experimental,
183 and will almost certainly change in incompatible ways in future
186 .. option:: -aux-info {filename}
188 Output to the given filename prototyped declarations for all functions
189 declared and/or defined in a translation unit, including those in header
190 files. This option is silently ignored in any language other than C.
192 Besides declarations, the file indicates, in comments, the origin of
193 each declaration (source file and line), whether the declaration was
194 implicit, prototyped or unprototyped (:samp:`I`, :samp:`N` for new or
195 :samp:`O` for old, respectively, in the first character after the line
196 number and the colon), and whether it came from a declaration or a
197 definition (:samp:`C` or :samp:`F`, respectively, in the following
198 character). In the case of function definitions, a K&R-style list of
199 arguments followed by their declarations is also provided, inside
200 comments, after the declaration.
204 Do not recognize ``asm``, ``inline`` or ``typeof`` as a
205 keyword, so that code can use these words as identifiers. You can use
206 the keywords ``__asm__``, ``__inline__`` and ``__typeof__``
207 instead. In C, :option:`-ansi` implies :option:`-fno-asm`.
209 In C++, ``inline`` is a standard keyword and is not affected by
210 this switch. You may want to use the :option:`-fno-gnu-keywords` flag
211 instead, which disables ``typeof`` but not ``asm`` and
212 ``inline``. In C99 mode (:option:`-std=c99` or :option:`-std=gnu99`),
213 this switch only affects the ``asm`` and ``typeof`` keywords,
214 since ``inline`` is a standard keyword in ISO C99. In C2X mode
215 (:option:`-std=c2x` or :option:`-std=gnu2x`), this switch only affects
216 the ``asm`` keyword, since ``typeof`` is a standard keyword in
221 Default setting; overrides :option:`-fno-asm`.
223 .. index:: built-in functions
225 .. option:: -fno-builtin, -fno-builtin-function
227 Don't recognize built-in functions that do not begin with
228 :samp:`__builtin_` as prefix. See :ref:`other-builtins`, for details of the functions affected,
229 including those which are not built-in functions when :option:`-ansi` or
230 :option:`-std` options for strict ISO C conformance are used because they
231 do not have an ISO standard meaning.
233 GCC normally generates special code to handle certain built-in functions
234 more efficiently; for instance, calls to ``alloca`` may become single
235 instructions which adjust the stack directly, and calls to ``memcpy``
236 may become inline copy loops. The resulting code is often both smaller
237 and faster, but since the function calls no longer appear as such, you
238 cannot set a breakpoint on those calls, nor can you change the behavior
239 of the functions by linking with a different library. In addition,
240 when a function is recognized as a built-in function, GCC may use
241 information about that function to warn about problems with calls to
242 that function, or to generate more efficient code, even if the
243 resulting code still contains calls to that function. For example,
244 warnings are given with :option:`-Wformat` for bad calls to
245 ``printf`` when ``printf`` is built in and ``strlen`` is
246 known not to modify global memory.
248 With the :option:`-fno-builtin-function` option
249 only the built-in function :samp:`{function}` is
250 disabled. :samp:`{function}` must not begin with :samp:`__builtin_`. If a
251 function is named that is not built-in in this version of GCC, this
252 option is ignored. There is no corresponding
253 :option:`-fbuiltin-function` option; if you wish to enable
254 built-in functions selectively when using :option:`-fno-builtin` or
255 :option:`-ffreestanding`, you may define macros such as:
259 #define abs(n) __builtin_abs ((n))
260 #define strcpy(d, s) __builtin_strcpy ((d), (s))
262 .. option:: -fbuiltin
264 Default setting; overrides :option:`-fno-builtin`.
266 .. option:: -fcond-mismatch
268 Allow conditional expressions with mismatched types in the second and
269 third arguments. The value of such an expression is void. This option
270 is not supported for C++.
272 .. index:: hosted environment
274 .. option:: -ffreestanding
276 Assert that compilation targets a freestanding environment. This
277 implies :option:`-fno-builtin`. A freestanding environment
278 is one in which the standard library may not exist, and program startup may
279 not necessarily be at ``main``. The most obvious example is an OS kernel.
280 This is equivalent to :option:`-fno-hosted`.
282 See :ref:`standards`, for details of
283 freestanding and hosted environments.
287 Enable parsing of function definitions marked with ``__GIMPLE``.
288 This is an experimental feature that allows unit testing of GIMPLE
293 When the option :option:`-fgnu-tm` is specified, the compiler
294 generates code for the Linux variant of Intel's current Transactional
295 Memory ABI specification document (Revision 1.1, May 6 2009). This is
296 an experimental feature whose interface may change in future versions
297 of GCC, as the official specification changes. Please note that not
298 all architectures are supported for this feature.
300 For more information on GCC's support for transactional memory,
301 see :ref:`libitm:enabling-libitm`.
303 Note that the transactional memory feature is not supported with
304 non-call exceptions (:option:`-fnon-call-exceptions`).
306 .. option:: -fgnu89-inline
308 The option :option:`-fgnu89-inline` tells GCC to use the traditional
309 GNU semantics for ``inline`` functions when in C99 mode.
311 Using this option is roughly equivalent to adding the
312 :fn-attr:`gnu_inline` function attribute to all inline functions
313 (see :ref:`function-attributes`).
315 The option :option:`-fno-gnu89-inline` explicitly tells GCC to use the
316 C99 semantics for ``inline`` when in C99 or gnu99 mode (i.e., it
317 specifies the default behavior).
318 This option is not supported in :option:`-std=c90` or
319 :option:`-std=gnu90` mode.
321 The preprocessor macros ``__GNUC_GNU_INLINE__`` and
322 ``__GNUC_STDC_INLINE__`` may be used to check which semantics are
323 in effect for ``inline`` functions. See :ref:`cpp:common-predefined-macros`.
325 .. index:: hosted environment
329 Assert that compilation targets a hosted environment. This implies
330 :option:`-fbuiltin`. A hosted environment is one in which the
331 entire standard library is available, and in which ``main`` has a return
332 type of ``int``. Examples are nearly everything except a kernel.
333 This is equivalent to :option:`-fno-freestanding`.
335 .. option:: -flax-vector-conversions
337 Allow implicit conversions between vectors with differing numbers of
338 elements and/or incompatible element types. This option should not be
341 .. option:: -fms-extensions
343 Accept some non-standard constructs used in Microsoft header files.
345 In C++ code, this allows member names in structures to be similar
346 to previous types declarations.
355 Some cases of unnamed fields in structures and unions are only
356 accepted with this option. See :ref:`unnamed-fields`, for details.
358 Note that this option is off for all targets except for x86
359 targets using ms-abi.
361 .. index:: Offloading targets, OpenACC offloading targets, OpenMP offloading targets
363 .. option:: -foffload=disable
365 Specify for which OpenMP and OpenACC offload targets code should be generated.
366 The default behavior, equivalent to :option:`-foffload=default`, is to generate
367 code for all supported offload targets. The :option:`-foffload=disable` form
368 generates code only for the host fallback, while
369 :option:`-foffload=target-list` generates code only for the specified
370 comma-separated list of offload targets.
372 Offload targets are specified in GCC's internal target-triplet format. You can
373 run the compiler with :option:`-v` to show the list of configured offload targets
374 under ``OFFLOAD_TARGET_NAMES``.
376 .. index:: Offloading options, OpenACC offloading options, OpenMP offloading options
378 .. option:: -foffload-options={options}
380 With :option:`-foffload-options=options`, GCC passes the specified
381 :samp:`{options}` to the compilers for all enabled offloading targets. You can
382 specify options that apply only to a specific target or targets by using
383 the :option:`-foffload-options=target-list=options` form. The
384 :samp:`{target-list}` is a comma-separated list in the same format as for the
385 :option:`-foffload=` option.
387 Typical command lines are
389 :option:`-foffload-options=-lgfortran` :option:`-foffload-options=-lm`
390 :option:`-foffload-options="-lgfortran-lm` :option:`-lm"` :option:`-foffload-options=nvptx-none=-latomic`
391 :option:`-foffload-options=amdgcn-amdhsa=-march=gfx906` :option:`-foffload-options=-lm`
393 .. index:: OpenACC accelerator programming
395 .. option:: -fopenacc
397 Enable handling of OpenACC directives ``#pragma acc`` in C/C++ and
398 ``!$acc`` in Fortran. When :option:`-fopenacc` is specified, the
399 compiler generates accelerated code according to the OpenACC Application
400 Programming Interface v2.6 https://www.openacc.org. This option
401 implies :option:`-pthread`, and thus is only supported on targets that
402 have support for :option:`-pthread`.
404 .. index:: OpenACC accelerator programming
406 .. option:: -fopenacc-dim={geom}
408 Specify default compute dimensions for parallel offload regions that do
409 not explicitly specify. The :samp:`{geom}` value is a triple of
410 ':'-separated sizes, in order 'gang', 'worker' and, 'vector'. A size
411 can be omitted, to use a target-specific default value.
413 .. index:: OpenMP parallel
417 Enable handling of OpenMP directives ``#pragma omp`` in C/C++,
418 ``[[omp::directive(...)]]`` and ``[[omp::sequence(...)]]`` in C++ and
419 ``!$omp`` in Fortran. When :option:`-fopenmp` is specified, the
420 compiler generates parallel code according to the OpenMP Application
421 Program Interface v4.5 https://www.openmp.org. This option
422 implies :option:`-pthread`, and thus is only supported on targets that
423 have support for :option:`-pthread`. :option:`-fopenmp` implies
424 :option:`-fopenmp-simd`.
426 .. index:: OpenMP SIMD, SIMD
428 .. option:: -fopenmp-simd
430 Enable handling of OpenMP's :gcc-attr:`simd`, ``declare simd``,
431 ``declare reduction``, ``assume``, ``ordered``, ``scan``,
432 ``loop`` directives and combined or composite directives with
433 :gcc-attr:`simd` as constituent with ``#pragma omp`` in C/C++,
434 ``[[omp::directive(...)]]`` and ``[[omp::sequence(...)]]`` in C++
435 and ``!$omp`` in Fortran. Other OpenMP directives are ignored.
437 .. option:: -fpermitted-flt-eval-methods={style}
439 ISO/IEC TS 18661-3 defines new permissible values for
440 ``FLT_EVAL_METHOD`` that indicate that operations and constants with
441 a semantic type that is an interchange or extended format should be
442 evaluated to the precision and range of that type. These new values are
443 a superset of those permitted under C99/C11, which does not specify the
444 meaning of other positive values of ``FLT_EVAL_METHOD``. As such, code
445 conforming to C11 may not have been written expecting the possibility of
448 :option:`-fpermitted-flt-eval-methods` specifies whether the compiler
449 should allow only the values of ``FLT_EVAL_METHOD`` specified in C99/C11,
450 or the extended set of values specified in ISO/IEC TS 18661-3.
452 :samp:`{style}` is either ``c11`` or ``ts-18661-3`` as appropriate.
454 The default when in a standards compliant mode (:option:`-std=c11` or similar)
455 is :option:`-fpermitted-flt-eval-methods=c11`. The default when in a GNU
456 dialect (:option:`-std=gnu11` or similar) is
457 :option:`-fpermitted-flt-eval-methods=ts-18661-3`.
459 .. option:: -fplan9-extensions
461 Accept some non-standard constructs used in Plan 9 code.
463 This enables :option:`-fms-extensions`, permits passing pointers to
464 structures with anonymous fields to functions that expect pointers to
465 elements of the type of the field, and permits referring to anonymous
466 fields declared using a typedef. See :ref:`unnamed-fields`, for details. This is only
467 supported for C, not C++.
469 .. option:: -fsigned-bitfields, -funsigned-bitfields, -fno-signed-bitfields, -fno-unsigned-bitfields
471 These options control whether a bit-field is signed or unsigned, when the
472 declaration does not use either ``signed`` or ``unsigned``. By
473 default, such a bit-field is signed, because this is consistent: the
474 basic integer types such as ``int`` are signed types.
476 .. option:: -fsigned-char
478 Let the type ``char`` be signed, like ``signed char``.
480 Note that this is equivalent to :option:`-fno-unsigned-char`, which is
481 the negative form of :option:`-funsigned-char`. Likewise, the option
482 :option:`-fno-signed-char` is equivalent to :option:`-funsigned-char`.
484 .. option:: -funsigned-char
486 Let the type ``char`` be unsigned, like ``unsigned char``.
488 Each kind of machine has a default for what ``char`` should
489 be. It is either like ``unsigned char`` by default or like
490 ``signed char`` by default.
492 Ideally, a portable program should always use ``signed char`` or
493 ``unsigned char`` when it depends on the signedness of an object.
494 But many programs have been written to use plain ``char`` and
495 expect it to be signed, or expect it to be unsigned, depending on the
496 machines they were written for. This option, and its inverse, let you
497 make such a program work with the opposite default.
499 The type ``char`` is always a distinct type from each of
500 ``signed char`` or ``unsigned char``, even though its behavior
501 is always just like one of those two.
503 .. option:: -fstrict-flex-arrays
505 Control when to treat the trailing array of a structure as a flexible array
506 member for the purpose of accessing the elements of such an array.
507 The positive form is equivalent to :option:`-fstrict-flex-arrays=3`, which is the
508 strictest. A trailing array is treated as a flexible array member only when it
509 is declared as a flexible array member per C99 standard onwards.
510 The negative form is equivalent to :option:`-fstrict-flex-arrays=0`, which is the
511 least strict. All trailing arrays of structures are treated as flexible array
514 .. option:: -fno-strict-flex-arrays
516 Default setting; overrides :option:`-fstrict-flex-arrays`.
518 .. index:: fstrict-flex-arrays=level
520 .. option:: -fstrict-flex-arrays={level}
522 Control when to treat the trailing array of a structure as a flexible array
523 member for the purpose of accessing the elements of such an array. The value
524 of :samp:`{level}` controls the level of strictness.
526 The possible values of :samp:`{level}` are the same as for the
527 ``strict_flex_array`` attribute (see :ref:`variable-attributes`).
529 You can control this behavior for a specific trailing array field of a
530 structure by using the variable attribute ``strict_flex_array`` attribute
531 (see :ref:`variable-attributes`).
533 .. option:: -fsso-struct={endianness}
535 Set the default scalar storage order of structures and unions to the
536 specified endianness. The accepted values are :samp:`big-endian`,
537 :samp:`little-endian` and :samp:`native` for the native endianness of
538 the target (the default). This option is not supported for C++.
542 The :option:`-fsso-struct` switch causes GCC to generate
543 code that is not binary compatible with code generated without it if the
544 specified endianness is not the native endianness of the target.