GCC Command-Line Options
This part of the documentation is a modified version of the Command-Line Options section of the GCC
Manual. Therefore it is licensed under the GNU Free Documentation License.
This section describes the options supported by gcc
, the driver program of the GNU Compiler Collection, whose C compiler and assembler are used here. This program is called either by tigcc
or by the IDE. tigcc
simulates
some of these options itself, namely '-E', '-S', and '-c', and it also has some additional ones. In the IDE, there is an item in the project settings where you can set the options described here, with some
exceptions, including the switches mentioned above.
TIGCC normally does preprocessing, compilation, assembly and linking all in one step, and finally produces a file which is executable on the calculator. The "overall options" allow you to stop this process at an intermediate stage. For example, the '-c' option
says not to run the linker. Then the output consists of object files output by the assembler.
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.
In fact, only those options which may be more or less useful with TIGCC are mentioned here (although we didn't check whether all of them are really usable in TIGCC). For more info about standard options that are recognized by the compiler, read the official
manual.
We suggest that you use the '-O2' switch in all of your compilations; it increases speed and decreases the program size at the cost of compilation time.
tigcc
accepts options and file names as operands. Many options have multi-letter names; therefore multiple single-letter options may not be grouped: '-dr' is very different from '-d -r'.
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 '-L' more than once, the directories are searched in
the order specified.
Many options have long names starting with '-f' or with '-W' - for example, '-fforce-mem', '-fstrength-reduce', '-Wformat' and so on. Most of these have both positive and negative
forms; the negative form of '-ffoo'would be '-fno-foo'. This manual documents only one of these two forms, whichever one is not the default.
- Options Available in the Command Line Compiler
- Options Controlling the Kind of Output
- Options Controlling C Dialect
- Options to Request or Suppress Warnings
- Options for Debugging Your Program
- Options That Control Optimization
- Options Controlling the Preprocessor
- Passing Options to the Assembler and Linker
- Options for Directory Search
- GCC Spec Strings
- M680x0 Target Options
- Options for Code Generation Conventions
- Environment Variables Affecting GCC
- History
- GNU General Public License
- GNU Free Documentation License
- Funding Free Software
Original author: Free Software Foundation, Inc.
Authors of the modifications: Zeljko Juric, Sebastian Reichelt, and Kevin Kofler
Published by the TIGCC Team.
See the History section for details and copyright information.
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;
with the Invariant Sections being "GNU General Public License" and "Funding Free Software", the Front-Cover texts being (a) (see below), and
with the Back-Cover Texts being (b) (see below). A copy of the license is included in the section entitled "GNU Free Documentation License".
(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.
Options Available in the Command Line Compiler
These options apply only to the command line compiler. If you want to use the IDE instead, you do not need to worry about these topics.
tigcc
has an important difference to the standard program gcc
: tigcc
always overwrites assembly or object files. For example, if a file test.c
is compiled, the files test.s
and test.o
will
be created and overwritten if necessary, but they will automatically be deleted again if neither '-c' nor '-S' are specified.
Another important difference is that tigcc
always looks for libraries in the 'Lib'
subfolder of the installation.
-
-pack varname
-
Compress the file generated during compilation. varname is the name of the on-calc packed variable. Although varname cannot have an extension, the variable on the calculator will always have the extension
ppg
. varnamecannot
be the same as the on-calc name of the program itself. When you use this switch, two files will be created; one with the extension.89y
or.9xy
, and one.89z
or.9xz
file.This option comes from Thomas Nussbaumer's TIGCC Tools Suite, where this feature is called "ExePack Technology." You can read about it on the official TI-Chess Team site.
-
-q
-
Keep as quiet as possible while assembling and linking. This option is not needed by the compiler because it is always quiet, but the linker and especially the assembler output some information.
-
-v0
-
This switch is an addition to the '-v' switch. It tells TIGCC to output only the commands that are run directly. This was the default in some previous releases.
-
-g
-
The '-g' switch in GCC turns on debugging information in the preferred format for the target. In TIGCC, this is DWARF 2, which can be used with a GDB-enabled TiEmu.
-
-standalone
-
Do not link against
tigcc.a
. All of GCC's internal functions are implemented in this library, as well as all non-TIOS functions. Using one of these will result in an error from the linker. -
-ar
-
Create an archive (a static library) instead of a program. The resulting file will have an
.a
ending. -
-bsr
-
This option is ignored for compatibility.
In addition to these options, the tigcc
program also accepts most of the linker options.
Options Controlling the Kind of Output
Compilation can involve up to four stages: preprocessing, compilation proper, assembly and linking, always in that order. The first three stages apply to an individual source file, and
end by producing an object file; linking combines all the object files (those newly compiled, and those specified as input) into an executable file.
For any given input file, the file name suffix determines what kind of compilation is done (some of these apply only to TIGCC):
-
file.c
-
C source code which must be preprocessed.
-
file.s
-
GNU Assembler code.
-
file.S
-
GNU Assembler code which must be preprocessed.
-
file.asm
-
A68k Assembler code.
-
file.o
-
COFF object file to be linked using
ld
. -
file.a
-
Static library (function archive) to be linked using
ld
.
You can specify the input language explicitly with the '-x' option:
-
-x language
-
Specify explicitly the language 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 '-x' option. Possible
values for language are:c c-header cpp-output c++ c++-cpp-output objective-c objc-cpp-output assembler assembler-with-cpp ada f77 f77-cpp-input ratfor java treelang
-
-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 '-x' has not been used at all).
-
-pass-exit-codes
-
Normally the
gcc
program will exit with the code of 1 if any phase of the compiler returns a non-success return code. If you specify '-pass-exit-codes', thegcc
program will instead return with numerically highest
error produced by any phase that returned an error indication.
If you only want some of the stages of compilation, you can use '-x' (or filename suffixes) to tell gcc
where to start, and one of the options '-c', '-S',
or '-E' to say where gcc
is to stop. Note that some combinations (for example, '-x cpp-output -E') instruct gcc
to do nothing at all.
-
-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.
By default, the object file name for a source file is made by replacing the suffix
.c
,.i
,.s
, etc., with.o
.Unrecognized input files, not requiring compilation or assembly, are ignored.
-
-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.
By default, the assembler file name for a source file is made by replacing the suffix
.c
,.i
, etc., with.s
.Input files that don't require compilation are ignored.
-
-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.
Input files which don't require preprocessing are ignored.
-
-o file
-
Place output in file file. 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.
Since only one output file can be specified, it does not make sense to use '-o' when compiling more than one input file, unless you are producing an executable file as output.
If '-o' is not specified, the default is to put an executable file in
a.out
, the object file forsource.suffix
insource.o
, its assembler file insource.s
,
and all preprocessed C source on standard output. -
-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.
-
-###
-
Like '-v' 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.
-
-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 GNU assembler has no trouble.
-
--help
-
Print (on the standard output) a description of the command line options understood by
gcc
. If the '-v' option is also specified then '--help' will also be passed on to the various processes invoked bygcc
,
so that they can display the command line options they accept. If the '-W' option is also specified then command line options which have no documentation associated with them will also be displayed. -
--target-help
-
Print (on the standard output) a description of target specific command line options for each tool.
-
--version
-
Display the version number and copyrights of the invoked GCC.
Options Controlling C Dialect
The following options control the dialect of C that the compiler accepts:
-
-ansi
-
Support all ISO C89 programs. This turns off certain features of GCC that are incompatible with ISO C89, such as the
asm
andtypeof
keywords, and some predefined macros that identify the type of system you are using. It also enables
the undesirable and rarely used ISO trigraph feature, and disables recognition of C++ style//
comments as well as theinline
keyword.The alternate keywords
__asm__
,__extension__
,__inline__
and__typeof__
continue to work despite '-ansi'. You would not want to use them in an ISO C program, of course, but it is useful to
put them in header files that might be included in compilations done with '-ansi'. Alternate predefined macros such as__unix__
are also available, with or without '-ansi'.The '-ansi' option does not cause non-ISO programs to be rejected gratuitously. For that, '-pedantic' is required in addition to '-ansi'. See Warning
Options.The macro
__STRICT_ANSI__
is predefined when the '-ansi' option is used. Some header files may notice this macro and refrain from declaring certain functions or defining certain macros that the ISO standard doesn't call for; this
is to avoid interfering with any programs that might use these names for other things.Functions which would normally be built in but do not have semantics defined by ISO C (such as alloca) are not built-in functions with '-ansi' is used. See Other
built-in functions provided by GCC for details of the functions affected.Note: At the moment, the TIGCC library depends heavily on GNU C extensions, so you cannot use the '-ansi' switch in TIGCC.
-
-std=standard
-
Determine the language standard. A value for standard must be provided; provided; possible values are
-
c89
iso9899:1990 -
ISO C90 (same as '-ansi').
-
iso9899:199409
-
ISO C90 as modified in amendment 1.
-
c99
c9x
iso9899:1999
iso9899:199x -
ISO C99. Note that this standard is not yet fully supported; see http://gcc.gnu.org/gcc-3.3/c99status.html for more information. The names
c9x
andiso9899:199x
are deprecated. -
gnu89
-
Default, ISO C90 plus GNU extensions (including some C99 features).
-
gnu99
gnu9x -
ISO C99 plus GNU extensions. When ISO C99 is fully implemented in GCC, this will become the default. The name
gnu9x
is deprecated.
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
__restrict__
even when '-std=c99' is not
specified.The '-std' options specifying some version of ISO C have the same effects as '-ansi', except that features that were not in ISO C90 but are in the specified version (for example,
//
comments and theinline
keyword
in ISO C99) are not disabled. -
-
-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.
Besides declarations, the file indicates, in comments, the origin of each declaration (source file and line), whether the declaration was implicit, prototyped or unprototyped (
I
,N
for new orO
for old, respectively, in
the first character after the line number and the colon), and whether it came from a declaration or a definition (C
orF
, 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. -
-fno-asm
-
Do not recognize
asm
,inline
ortypeof
as a keyword, so that code can use these words as identifiers. You can use the keywords__asm__
,__inline__
and__typeof__
instead. '-ansi' implies '-fno-asm'. -
-fno-builtin
-fno-builtin-function -
Don't recognize built-in functions that do not begin with
__builtin_
as prefix. See Other built-in functions provided by GCC for details of the functions affected, including those
which are not built-in functions when '-ansi' or'-std' options for strict ISO C conformance are used because they do not have an ISO standard meaning.GCC normally generates special code to handle certain built-in functions more efficiently; for instance, calls to alloca may become single instructions that adjust the stack directly. 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.With the '-fno-builtin-function' option, only the built-in function function is disabled. function must not begin with
__builtin_
. If a function is named this is not built-in in this version of GCC, this
option is ignored. There is no corresponding '-fbuiltin-function' option; if you wish to enable built-in functions selectively when using '-fno-builtin' or '-ffreestanding', you may define macros
such as:#define abs(n) __builtin_abs ((n)) #define strcpy(d, s) __builtin_strcpy ((d), (s))
-
-fhosted
-
Assert that compilation takes place in a hosted environment. This implies '-fbuiltin'. A hosted environment is one in which the entire standard library is available, and in which
main
has a return type ofint
. Examples
are nearly everything except a kernel. This is equivalent to '-fno-freestanding'.Although TI calculators are not really hosted environments, '-fhosted' is kept as the default.
-
-ffreestanding
-
Assert that compilation takes place in a freestanding environment. This implies '-fno-builtin'. A freestanding environment is one in which the standard library may not exist, and program startup may not necessarily be at
main
.
The most obvious example is an OS kernel. This is equivalent to '-fno-hosted'. -
-fms-extensions
-
Accept some non-standard constructs used in Microsoft header files.
-
-trigraphs
-
Support ISO C trigraphs. The '-ansi' option (and '-std' options for strict ISO C conformance) implies '-trigraphs'. See Options Controlling the Preprocessor for
more information. -
-no-integrated-cpp
-
Performs a compilation in two passes: preprocessing and compiling. This option allows a user supplied "cc1" via the '-B' 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 preprocessor.The semantics of this option will change if "cc1", "cc1plus", and "cc1obj" are merged.
-
-traditional
-traditional-cpp -
Formerly, these options caused GCC to attempt to emulate a pre-standard C compiler. They are now only supported with the '-E' switch. The preprocessor continues to support a pre-standard
mode. -
-fcond-mismatch
-
Allow conditional expressions with mismatched types in the second and third arguments. The value of such an expression is void.
-
-funsigned-char
-
Let the type
char
be unsigned, likeunsigned char
. In TIGCC, the default issigned char
.Ideally, a portable program should always use
signed char
orunsigned char
when it depends on the signedness of an object. But many programs have been written to use plainchar
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.The type
char
is always a distinct type from each ofsigned char
orunsigned char
, even though its behavior is always just like one of those two. -
-fsigned-char
-
Let the type
char
be signed, likesigned char
.Note that this is equivalent to '-fno-unsigned-char', which is the negative form of '-funsigned-char'. Likewise, the option '-fno-signed-char' is equivalent to '-funsigned-char'.
-
-fsigned-bitfields
-funsigned-bitfields
-fno-signed-bitfields
-fno-unsigned-bitfields -
These options control whether a bit-field is signed or unsigned, when the declaration does not use either
signed
orunsigned
. By default, such a bit-field is signed, because this is consistent: the basic integer types such asint
are
signed types. -
-fwritable-strings
-
Store string constants in the writable data segment and don't uniquize them. This is for compatibility with old programs which assume they can write into string constants.
Writing into string constants is a very bad idea; "constants" should be constant.
Options to Request or Suppress Warnings
Warnings are diagnostic messages that report constructions which are not inherently erroneous but which are risky or suggest there may have been an error.
You can request many specific warnings with options beginning '-W', for example '-Wimplicit' to request warnings on implicit declarations. Each of these specific warning options also has a negative form beginning '-Wno-' to
turn off warnings; for example, '-Wno-implicit'. This manual lists only one of the two forms, whichever is not the default.
The following options control the amount and kinds of warnings produced by GCC.
-
-fsyntax-only
-
Check the code for syntax errors, but don't do anything beyond that.
-
-pedantic
-
Issue all the warnings demanded by strict ISO C; reject all programs that use forbidden extensions, and some other programs that do not follow ISO C. This option follows the version of the ISO C standard specified by any'-std' option used.
Valid ISO C programs should compile properly with or without this option (though a rare few will require '-ansi' or a '-std' option specifying the required version of ISO C). However, without this option, certain GNU extensions
and traditional C features are supported as well. With this option, they are rejected.'-pedantic' does not cause warning messages for use of the alternate keywords whose names begin and end with
__
. Pedantic warnings are also disabled in the expression that follows__extension__
. However, only system
header files should use these escape routes; application programs should avoid them. See Alternate Keywords.Some users try to use '-pedantic' to check programs for strict ISO C conformance. They soon find that it does not do quite what they want: it finds some non-ISO practices, but not all - only those for which ISO C requiresa diagnostic,
and some others for which diagnostics have been added.A feature to report any failure to conform to ISO C might be useful in some instances, but would require considerable additional work and would be quite different from '-pedantic'. The GNU team doesn't have plans to support such a feature in
the near future.Where the standard specified with '-std' represents a GNU extended dialect of C, such as
gnu89
orgnu99
, there is a corresponding base standard, the version of ISO C on which the GNU extended dialect is based.
Warnings from '-pedantic' are given where they are required by the base standard. (It would not make sense for such warnings to be given only for features not in the specified GNU C dialect, since by definition the GNU dialects of C include
all features the compiler supports with the given option, and there would be nothing to warn about.) -
-pedantic-errors
-
Like '-pedantic', except that errors are produced rather than warnings.
-
-w
-
Inhibit all warning messages.
-
-Wno-import
-
Inhibit warning messages about the use of
#import
. -
-Wchar-subscripts
-
Warn if an array subscript has type
char
. This is a common cause of error, as programmers often forget that this type is signed on some machines. -
-Wcomment
-
Warn whenever a comment-start sequence
/*
appears in a/*
comment, or whenever a Backslash-Newline appears in a//
comment. -
-Wformat
-
Check calls to printf and scanf, etc., to make sure that the arguments supplied have types appropriate to the format string specified,
and that the conversions specified in the format string make sense. This includes standard functions, and others specified by format attributes (see format).Since '-Wformat' also checks for null format arguments for several functions, '-Wformat' also implies '-Wnonnull'.
'-Wformat' is included in '-Wall'. For more control over some aspects of format checking, the options '-Wno-format-extra-args', '-Wno-format-zero-length', '-Wformat-nonliteral', '-Wformat-security',
and '-Wformat=2' are available, but are not included in '-Wall'. -
-Wno-format-extra-args
-
If '-Wformat' is specified, do not warn about excess arguments to a printf or scanf format function. The C standard specifies
that such arguments are ignored. -
-Wno-format-zero-length
-
If '-Wformat' is specified, do not warn about zero-length formats. The C standard specifies that zero-length formats are allowed.
-
-Wformat-nonliteral
-
If '-Wformat' is specified, also warn if the format string is not a string literal and so cannot be checked, unless the format function takes its format arguments as a va_list.
-
-Wformat-security
-
If '-Wformat' is specified, also warn about uses of format functions that represent possible security problems. At present, this warns about calls to printf and scanf functions
where the format string is not a string literal and there are no format arguments, as inprintf (foo);
. This may be a security hole if the format string came from untrusted input and contains%n
. (This is currently a subset of what '-Wformat-nonliteral' warns
about, but in future warnings may be added to '-Wformat-security' that are not included in '-Wformat-nonliteral'.) -
-Wformat=2
-
Enable '-Wformat' plus format checks not included in '-Wformat'. Currently equivalent to '-Wformat -Wformat-nonliteral -Wformat-security'.
-
-Wnonnull
-
Enable warning about passing a null pointer for arguments marked as requiring a non-null value by the
nonnull
function attribute.'-Wnonnull' is included in '-Wall' and '-Wformat'. It can be disabled with the '-Wno-nonnull' option.
-
-Wimplicit-int
-
Warn when a declaration does not specify a type.
-
-Wimplicit-function-declaration
-Werror-implicit-function-declaration -
Give a warning (or error) whenever a function is used before being declared.
-
-Wimplicit
-
Same as '-Wimplicit-int -Wimplicit-function-declaration'.
-
-Wmissing-braces
-
Warn if an aggregate or union initializer is not fully bracketed. In the following example, the initializer for
a
is not fully bracketed, but that forb
is fully bracketed.int a[2][2] = { 0, 1, 2, 3 }; int b[2][2] = { { 0, 1 }, { 2, 3 } };
-
-Wparentheses
-
Warn if parentheses are omitted in certain contexts, such as when there is an assignment in a context where a truth value is expected, or when operators are nested whose precedence people often get confused about.
Also warn about constructions where there may be confusion to which
if
statement anelse
branch belongs. Here is
an example of such a case:{ if (a) if (b) foo (); else bar (); }
In C, every
else
branch belongs to the innermost possibleif
statement, which in this example isif (b)
. This is often not what the programmer expected, as illustrated in the above example by the indentation the programmer
chose. When there is the potential for this confusion, GCC will issue a warning when this flag is specified. To eliminate the warning, add explicit braces around the innermostif
statement so there is no way theelse
could belong
to the enclosingif
. The resulting code would look like this:{ if (a) { if (b) foo (); else bar (); } }
-
-Wsequence-point
-
Warn about code that may have undefined semantics because of violations of sequence point rules in the C standard.
The C standard defines the order in which expressions in a C program are evaluated in terms of sequence points, which represent a partial ordering between the execution of parts of the program: those executed before the sequence point, and those executed
after it. These occur after the evaluation of a full expression (one which is not part of a larger expression), after the evaluation of the first operand of a&&
,||
,? :
or,
(comma) operator, before a function
is called (but after the evaluation of its arguments and the expression denoting the called function), and in certain other places. Other than as expressed by the sequence point rules, the order of evaluation of subexpressions of an expression is not specified.
All these rules describe only a partial order rather than a total order, since, for example, if two functions are called within one expression with no sequence point between them, the order in which the functions are called is not specified. However, the standards
committee have ruled that function calls do not overlap.It is not specified when between sequence points modifications to the values of objects take effect. Programs whose behavior depends on this have undefined behavior; the C standard specifies that "Between the previous and next sequence point an object shall
have its stored value modified at most once by the evaluation of an expression. Furthermore, the prior value shall be read only to determine the value to be stored.". If a program breaks these rules, the results on any particular implementation are entirely
unpredictable.Examples of code with undefined behavior are
a = a++;
,a[n] = b[n++]
anda[i++] = i;
. Some more complicated cases are not diagnosed by this option, and it may give an occasional false positive result, but in general it
has been found fairly effective at detecting this sort of problem in programs.The C standard is worded confusingly, therefore there is some debate over the precise meaning of the sequence point rules in subtle cases. Links to discussions of the problem, including proposed formal definitions, may be found on the GCC readings page, at http://gcc.gnu.org/readings.html.
-
-Wreturn-type
-
Warn whenever a function is defined with a return-type that defaults to
int
. Also warn about anyreturn
statement with no return-value in a function whose return-type is
notvoid
. -
-Wswitch
-
Warn whenever a
switch
statement has an index of enumeral type and lacks acase
for one or more of the
named codes of that enumeration. (The presence of adefault
label prevents this warning.)case
labels outside the enumeration range also provoke warnings when this option is used. -
-Wswitch-default
-
Warn whenever a
switch
statement does not have adefault
case. -
-Wswitch-enum
-
Warn whenever a
switch
statement has an index of enumeral type and lacks acase
for one or more of the named codes of that enumeration.case
labels outside the enumeration range also provoke warnings when this option
is used. -
-Wtrigraphs
-
Warn if any trigraphs are encountered that might change the meaning of the program (trigraphs within comments are not warned about). For more information about trigraphs, see Options Controlling the
Preprocessor. -
-Wunused-function
-
Warn whenever a static function is declared but not defined or a non\-inline static function is unused.
To suppress this warning, use the
unused
attribute. -
-Wunused-label
-
Warn whenever a label is declared but not used.
To suppress this warning, use the
unused
attribute. -
-Wunused-parameter
-
Warn whenever a function parameter is unused aside from its declaration.
To suppress this warning, use the
unused
attribute. -
-Wunused-variable
-
Warn whenever a local variable or non-constant static variable is unused aside from its declaration
To suppress this warning, use the
unused
attribute. -
-Wunused-value
-
Warn whenever a statement computes a result that is explicitly not used.
To suppress this warning, cast the expression to
void
. -
-Wunused
-
All the above '-Wunused' options combined.
In order to get a warning about an unused function parameter, you must either specify '-W -Wunused' or separately specify '-Wunused-parameter'.
-
-Wuninitialized
-
Warn if an automatic variable is used without first being initialized or if a variable may be clobbered by a setjmp call (I am not sure whether setjmp problems
may be detected in TIGCC).These warnings are possible only in optimizing compilation, because they require data flow information that is computed only when optimizing. If you don't specify '-O', you simply won't get these warnings.
These warnings occur only for variables that are candidates for register allocation. Therefore, they do not occur for a variable that is declared
volatile
, or whose address is taken,
or whose size is other than 1, 2, 4 or 8 bytes. Also, they do not occur for structures, unions or arrays, even when they are in registers.Note that there may be no warning about a variable that is used only to compute a value that itself is never used, because such computations may be deleted by data flow analysis before the warnings are printed.
These warnings are made optional because GCC is not smart enough to see all the reasons why the code might be correct despite appearing to have an error. Here is one example of how this can happen:
{ int x; switch (y) { case 1: x = 1; break; case 2: x = 4; break; case 3: x = 5; } foo (x); }
If the value of y is always 1, 2 or 3, then x is always initialized, but GCC doesn't know this. Here is another common case:
{ int save_y; if (change_y) save_y = y, y = new_y; ... if (change_y) y = save_y; }
This has no bug because save_y is used only if it is set.
This option also warns when a non-volatile automatic variable might be changed by a call to longjmp. These warnings as well are possible only in optimizing compilation (although I am not sure whether
they can be caught at all in TIGCC).The compiler sees only the calls to setjmp. It cannot know where longjmp will be called; in fact, an interrupt handler could call it at
any point in the code. As a result, you may get a warning even when there is in fact no problem because longjmp cannot in fact be called at the place which would cause a problem.Some spurious warnings can be avoided if you declare all the functions you use that never return as noreturn.
-
-Wunknown-pragmas
-
Warn when a
#pragma
directive is encountered which is not understood by GCC. If this command line option is used, warnings will even be issued for unknown pragmas in system header files.
This is not the case if the warnings were only enabled by the '-Wall' command line option. -
-Wstrict-aliasing
-
This option is only active when '-fstrict-aliasing' is active. It warns about code which might break the strict aliasing rules that the compiler is using for optimization. The warning does not catch all cases, but does attempt to catch the
more common pitfalls. It is included in '-Wall'. -
-Wall
-
All of the above '-W' options combined. This enables all the warnings about constructions that some users consider questionable, and that are easy to avoid (or modify to prevent the warning), even in conjunction with macros.
The following '-W...' options are not implied by '-Wall'. Some of them warn about constructions that users generally do not consider questionable, but
which occasionally you might wish to check for; others warn about constructions that are necessary or hard to avoid in some cases, and there is no simple way to modify the code to suppress the warning.
-
-W
-
Print extra warning messages for these events:
-
A function can return either with or without a value. (Falling off the end of the function body is considered returning without a value.) For example, this function would evoke such a warning:
foo (a) { if (a > 0) return a; }
-
An expression-statement or the left-hand side of a comma expression contains no side effects. To suppress the warning, cast the unused expression to void. For example, an expression such as
x[i,j]
will cause a warning, butx[(void)i,j]
will
not. -
An unsigned value is compared against zero with
<
or<=
. -
A comparison like
x<=y<=z
appears; this is equivalent to(x<=y ? 1 : 0) <= z
, which is a different interpretation from that of ordinary mathematical notation. -
Storage-class specifiers like
static
are not the first things in a declaration. According to the C Standard, this usage is obsolescent. -
The return type of a function has a type qualifier such as
const
. Such a type qualifier has no effect, since the value returned by a function is not an lvalue. (But don't warn about the GNU extension ofvolatile void
return types.
That extension will be warned about if '-pedantic' is specified.) -
If '-Wall' or '-Wunused' is also specified, warn about unused arguments.
-
A comparison between signed and unsigned values could produce an incorrect result when the signed value is converted to unsigned. (But don't warn if '-Wno-sign-compare' is also specified.)
-
An aggregate has a partly bracketed initializer. For example, the following code would evoke such a warning, because braces are missing around the initializer for x.h:
struct s { int f, g; }; struct t { struct s h; int i; }; struct t x = { 1, 2, 3 };
-
An aggregate has an initializer which does not initialize all members. For example, the following code would cause such a warning, because x.h would be implicitly initialized to zero:
struct s { int f, g, h; }; struct s x = { 3, 4 };
-
-
-Wno-div-by-zero
-
Do not warn about compile-time integer division by zero. Floating point division by zero is not warned about, as it can be a legitimate way of obtaining infinities and NaNs.
-
-Wsystem-headers
-
Print warning messages for constructs found in system header files. Warnings from system headers are normally suppressed, on the assumption that they usually do not indicate real problems and would only make the compiler output harder to read. Using this
command line option tells GCC to emit warnings from system headers as if they occurred in user code. However, note that using '-Wall' in conjunction with this option will notwarn about unknown pragmas in system headers - for that, '-Wunknown-pragmas' must
also be used.Note that the TIGCC Library header files are not included as system header files.
-
-Wfloat-equal
-
Warn if floating point values are used in equality comparisons.
The idea behind this is that sometimes it is convenient (for the programmer) to consider floating-point values as approximations to infinitely precise real numbers. If you are doing this, then you need to compute (by analyzing the code, or in some other way)
the maximum or likely maximum error that the computation introduces, and allow for it when performing comparisons (and when producing output, but that's a different problem). In particular, instead of testing for equality, you would check to see whether the
two values have ranges that overlap; and this is done with the relational operators, so equality comparisons are probably mistaken. -
-Wtraditional
-
Warn about certain constructs that behave differently in traditional and ISO C. Also warn about ISO C constructs that have no traditional C equivalent, and/or problematic constructs which should be avoided.
-
Macro parameters that appear within string literals in the macro body. In traditional C macro replacement takes place within string literals, but does not in ISO C.
-
In traditional C, some preprocessor directives did not exist. Traditional preprocessors would only consider a line to be a directive if the
#
appeared in column 1 on the line. Therefore '-Wtraditional' warns about directives
that traditional C understands but would ignore because the#
does not appear as the first character on the line. It also suggests you hide directives like#pragma
not understood
by traditional C by indenting them. Some traditional implementations would not recognize#elif
, so it suggests avoiding it altogether. -
A function-like macro that appears without arguments.
-
The unary plus operator.
-
The
U
integer constant suffix, or theF
orL
floating point constant suffixes. (Traditional C does support theL
suffix on integer constants.) Note, these suffixes appear in macros defined in limits.h,
for example. -
A function declared external in one block and then used after the end of the block.
-
A non-
static
function declaration follows astatic
one. This construct is not accepted by some traditional C compilers. -
The ISO type of an integer constant has a different width or signedness from its traditional type. This warning is only issued if the base of the constant is 10, i.e. hexadecimal or octal values, which typically represent bit patterns, are not warned about.
-
Usage of ISO string concatenation is detected.
-
Initialization of automatic aggregates.
-
Identifier conflicts with labels. Traditional C lacks a separate namespace for labels.
-
Initialization of unions. If the initializer is zero, the warning is omitted. This is done under the assumption that the zero initializer in user code appears conditioned on e.g. __STDC__ to avoid
missing initializer warnings and relies on default initialization to zero in the traditional C case. -
Conversions by prototypes between fixed/floating point values and vice versa. The absence of these prototypes when compiling with traditional C would cause serious problems. This is a subset of the possible conversion warnings, for the full set use '-Wconversion'.
-
Use of ISO C style function definitions. This warning intentionally is not issued for prototype declarations or variadic functions because these ISO C features will appear in your code when using libiberty's traditional C compatibility macros,
PARAMS
andVPARAMS
.
This warning is also bypassed for nested functions because that feature is already a gcc extension and thus not relevant to traditional C compatibility.
-
-
-Wundef
-
Warn if an undefined identifier is evaluated in an
#if
directive. -
-Wendif-labels
-
Warn whenever an
#else
or an#endif
are followed by text. -
-Wshadow
-
Warn whenever a local variable shadows another local variable, parameter or global variable or whenever a built-in function is shadowed.
-
-Wlarger-than-len
-
Warn whenever an object of larger than len bytes is defined.
-
-Wpointer-arith
-
Warn about anything that depends on the "size of" a function type or of
void
. GNU C assigns these types a size of 1, for convenience in calculations withvoid*
pointers
and pointers to functions. -
-Wbad-function-cast
-
Warn whenever a function call is cast to a non-matching type. For example, warn if
int malloc()
is cast toanything *
. -
-Wcast-qual
-
Warn whenever a pointer is cast so as to remove a type qualifier from the target type. For example, warn if a
const char *
is cast to an ordinarychar *
. -
-Wcast-align
-
Warn whenever a pointer is cast such that the required alignment of the target is increased. For example, warn if a
char *
is cast to anint *
on machines where integers can only be accessed at two- or four-byte boundaries. -
-Wwrite-strings
-
When compiling C, give string constants the type
const char[length]
so that copying the address of one into a non-const
char *
pointer will get a warning; when compiling C++, warn about the deprecated conversion
from string constants tochar *
. These warnings will help you find at compile time code that can try to write into a string constant, but only if you have been very careful about usingconst
in declarations and prototypes. Otherwise,
it will just be a nuisance; this is why we did not make '-Wall' request these warnings. -
-Wconversion
-
Warn if a prototype causes a type conversion that is different from what would happen to the same argument in the absence of a prototype. This includes conversions of fixed point to floating and vice versa, and conversions changing the width or signedness
of a fixed point argument except when the same as the default promotion.Also, warn if a negative integer constant expression is implicitly converted to an unsigned type. For example, warn about the assignment
x = -1
ifx
is unsigned. But do not warn about explicit casts like(unsigned) -1
. -
-Wsign-compare
-
Warn when a comparison between signed and unsigned values could produce an incorrect result when the signed value is converted to unsigned. This warning is enabled by '-W', and by '-Wall' in C++ only.
-
-Waggregate-return
-
Warn if any functions that return structures or unions are defined or called.
-
-Wstrict-prototypes
-
Warn if a function is declared or defined without specifying the argument types. (An old-style function definition is permitted without a warning if preceded by a declaration which specifies the argument types.)
-
-Wmissing-prototypes
-
Warn if a global function is defined without a previous prototype declaration. This warning is issued even if the definition itself provides a prototype. The aim is to detect global functions that fail to be declared in header files.
-
-Wmissing-declarations (C only)
-
Warn if a global function is defined without a previous declaration. Do so even if the definition itself provides a prototype. Use this option to detect global functions that are not declared in header files.
-
-Wmissing-noreturn
-
Warn about functions which might be candidates for attribute noreturn. Note these are only possible candidates, not absolute ones. Care should be taken to manually verify functions actually
do not ever return before adding the noreturn attribute, otherwise subtle code generation bugs could be introduced. -
-Wmissing-format-attribute
-
If '-Wformat' is enabled, also warn about functions which might be candidates for format attributes. Note these are only possible candidates, not absolute ones. GCC will
guess that format attributes might be appropriate for any function that calls a function like vprintf or vscanf,
but this might not always be the case, and some functions for which format attributes are appropriate may not be detected. This option has no effect unless '-Wformat' is enabled
(possibly by '-Wall'). -
-Wno-multichar
-
Do not warn if a multicharacter constant (
'FOOF'
) is used. Usually they indicate a typo in the user's code, as