Mixed Declarations And Code; Declaring Attributes Of Functions - Red Hat ENTERPRISE LINUX 4 Manual

Hide thumbs Also See for ENTERPRISE LINUX 4:
Table of Contents

Advertisement

150

6.24. Mixed Declarations and Code

ISO C99 and ISO C++ allow declarations and code to be freely mixed within compound statements.
As an extension, GCC also allows this in C89 mode. For example, you could do:
int i;
/* ... */
i++;
int j = i + 2;
Each identifier is visible from where it is declared until the end of the enclosing block.

6.25. Declaring Attributes of Functions

In GNU C, you declare certain things about functions called in your program which help the compiler
optimize function calls and check your code more carefully.
The keyword
__attribute__
This keyword is followed by an attribute specification inside double parentheses. The
following attributes are currently defined for functions on all targets:
,
always_inline
pure
,
section
constructor
warn_unused_result
target systems. Other attributes, including
6.32 Specifying Attributes of Variables) and for types (Section 6.33 Specifying Attributes of Types).
You may also specify attributes with
them in header files without being concerned about a possible macro of the same name. For example,
you may use
__noreturn__
Section 6.26 Attribute Syntax, for details of the exact syntax for using attributes.
noreturn
A few standard library functions, such as
automatically. Some programs define their own functions that never return. You can declare them
to tell the compiler this fact. For example,
noreturn
void fatal () __attribute__ ((noreturn));
void
fatal (/* ... */)
{
/* ... */ /* Print error message. */ /* ... */
exit (1);
}
The
noreturn
mize without regard to what would happen if
code. More importantly, it helps avoid spurious warnings of uninitialized variables.
The
noreturn
marked function may still return to the caller by throwing an exception.
Do not assume that registers saved by the calling function are restored before calling the
function.
noreturn
It does not make sense for a
allows you to specify special attributes when making a declaration.
,
,
const
nothrow
,
destructor
and
. Several other attributes are defined for functions on particular
nonnull
preceding and following each keyword. This allows you to use
__
instead of
noreturn
keyword tells the compiler to assume that
keyword does not affect the exceptional path when that applies: a
noreturn
Chapter 6. Extensions to the C Language Family
,
,
format
format_arg
,
,
,
used
unused
deprecated
are supported for variables declarations (Section
section
.
and
abort
exit
ever did return. This makes slightly better
fatal
function to have a return type other than
noreturn
,
no_instrument_function
,
,
weak
malloc
, cannot return. GCC knows this
cannot return. It can then opti-
fatal
,
,
noinline
,
,
,
alias
-
noreturn
.
void

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the ENTERPRISE LINUX 4 and is the answer not in the manual?

Table of Contents