-
display the compiler version and copyrights
#> g++ --version
-
return the compiler version number
#> g++ -dumpversion
-
use the
-v
flag to see the flags gcc/g++ uses when calling its subprocesses -
Preprocessor
-
get the list of predefined defines
#> cpp -dM /dev/null
-
use
-Wp,-H
to get the indented list of included header files#> g++296 -Wp,-H -c -fPIC -DOPTIMAL -march=i686 -O2 -I/vobs-awa/AW4.3_src/src/include/stl -I/vobs-awa/AW4.3_src/src/include -I/usr/X11R6/include/ -I. -DLinux -D_XOPEN_SOURCE=600 -Wall -W -fmessage-length=0 -Wpointer-arith QueueRequest.c -o objects_i386_default/QueueRequest.o
-
__GNUC__
is defined when compiling C
__GNUG__
is defined when compiling C++ -
__FUNCTION__
function name as it appears in the source code
__PRETTY_FUNCTION__
pretty printed function name in a language specific fashion
-
get the list of predefined defines
-
Compiler
-
for AMD/Intel CPUs
compile in 32 bits mode (long
s and pointers are 32 bits)#> gcc -m32
long
s and pointers are 64 bits)#> gcc -m64
-
create a shared library
#> gcc -shared sample.c -o sample.so
-
for AMD/Intel CPUs
-
Linker
-
pass
option
as an option to the linker#> gcc -Xlinker option
-
pass
-
alloca
allocates some memory on the stack (exists in many other implementations other than gcc)
It is faster that usingmalloc
/free
, but the limit on the stack size may be low on some machine (this is done in order to catch early infinite recrusions) and there is no way to test for a failed allocation (the program will simply crash when trying to write data in a too large address). -
__buildin_constant_p
this a compiler intrinsic routine testing if its parameter is a constant
It is useful to write macros optimized when one of their parameters is a hard coded constant. -
__typeof__
this is a macro returning the type of its argument
It is useful when writing macros which are generic for several data types. -
__va_copy
copy ava_list
(there is no other way to portably walk through a variable parameter list twice)
-
use
-Wall -W
to get most warning messages (-W
has been deprecated by-Wextra
with gcc3.x) -
use
-fmessage-length=0
to be able to parse easily the warning messages
-
Function attributes
-
constructor
the function must be called beforemain
static void initialize() __attribute__ ((constructor));
-
destructor
the function must be called afterexit
-
noreturn
the function never returns (this allows some optimization, but also some code check: the compiler will warn if some code is present after calling this function) -
pure
pure function (no side effect, the function is simply computing a value from its parameter values and/or global variables) -
const
purer function (the function is computing a value from its parameter values) -
stdcall
the function itself will correct the stack when returning -
regparm(n)
number of parameters that shall be passed using registers (n <=3) -
no_instrument_function
the function will no be instrumented when the code is compiled with-finstrument-functions
-
deprecated
generates a deprecation warning every time this function is used
-
-
Type attributes
-
unused
avoid a warning indicating that a variable of this type is unused -
deprecated
generate a deprecation warning every time this type is used -
packed
attached to anenum
,struct
, orunion
type definition, specify that the minimum required memory be used to represent the type.typedef struct {
stamp_type stamp;
envelope_address_type address;
message_type message;
}
#if defined(Linux) // this is required to have the same layout in 32 and 64 bits
__attribute__ ((packed))
#endif //Linux
envelope_type; -
aligned (alignment)
specify a minimum alignment (in bytes) for variables of this type
-
-
Variable attributes
-
unused
avoid a warning indicating that the variable is unusedstatic const char *foobar [4]
#if defined(__GNUG__)
__attribute__ ((unused))
#endif // __GNUG__
= {
"a",
"b",
"c",
"d"
}; -
deprecated
generates a deprecation warning every time this variable is used
-