Prototypes And Old-Style Function Definitions - Red Hat ENTERPRISE LINUX 3 - USING GCC Using Instructions

Using the gnu compiler collection (gcc)
Hide thumbs Also See for ENTERPRISE LINUX 3 - USING GCC:
Table of Contents

Advertisement

146
For example,
void (__attribute__((noreturn)) ****f) (void);
specifies the type "pointer to pointer to pointer to pointer to non-returning function returning
As another example,
char *__attribute__((aligned(8))) *f;
specifies the type "pointer to 8-byte-aligned pointer to
most attributes; for example, the usage of
supported.
For compatibility with existing code written for compiler versions that did not implement attributes on
nested declarators, some laxity is allowed in the placing of attributes. If an attribute that only applies
to types is applied to a declaration, it will be treated as applying to the type of that declaration. If an
attribute that only applies to declarations is applied to the type of a declaration, it will be treated as
applying to that declaration; and, for compatibility with code placing the attributes immediately before
the identifier declared, such an attribute applied to a function return type will be treated as applying
to the function type, and such an attribute applied to an array element type will be treated as applying
to the array type. If an attribute that only applies to function types is applied to a pointer-to-function
type, it will be treated as applying to the pointer target type; if such an attribute is applied to a function
return type that is not a pointer-to-function type, it will be treated as applying to the function type.
6.28. Prototypes and Old-Style Function Definitions
GNU C extends ISO C to allow a function prototype to override a later old-style non-prototype defi-
nition. Consider the following example:
/* Use prototypes unless the compiler is old-fashioned.
#ifdef __STDC__
#define P(x) x
#else
#define P(x) ()
#endif
/* Prototype function declaration.
int isroot P((uid_t));
/* Old-style function definition.
int
isroot (x)
/* ??? lossage here ??? */
uid_t x;
{
return x == 0;
}
Suppose the type
uid_t
arguments in old-style non-prototype definitions are promoted. Therefore in this example the function
definition's argument is really an
This restriction of ISO C makes it hard to write code that is portable to traditional C compilers,
because the programmer does not know whether the
in cases like these GNU C allows a prototype to override a later old-style definition. More precisely, in
GNU C, a function prototype argument type overrides the argument type specified by a later old-style
definition if the former type is the same as the latter type before promotion. Thus in GNU C the above
example is equivalent to the following:
aligned
happens to be
short
, which does not match the prototype argument type of
int
Chapter 6. Extensions to the C Language Family
". Note again that this does not work with
char
and
noreturn
*/
*/
. ISO C does not allow this example, because subword
type is
uid_t
attributes given above is not yet
*/
,
, or
short
int
long
".
void
.
short
. Therefore,

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the ENTERPRISE LINUX 3 - USING GCC and is the answer not in the manual?

Questions and answers

Subscribe to Our Youtube Channel

This manual is also suitable for:

Enterprise linux 3

Table of Contents