This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

undocumented syntax for functions definitions with attributes


The following undocumented syntax was reported on the Debian bug
tracking system (tested with egcs-1.1.1).

From: Ian Jackson <ian@davenant.greenend.org.uk>

The function __attribute__((...)) extension in GCC is very useful.
However, it has something of a niggle in its use.

If the relevant declaration of a function is also its definition then
you cannot use __attribute__ in the way suggested by the examples in
the GCC manual; GCC rejects the `obvious' usage with a syntax error.

The manual does not give a formal definition of where function
attributes may appear, but the examples are all like
          int square (int) __attribute__ ((const));
suggesting that in a definition it should appear between the argument
list and the opening brace.

However, GCC does not accept that syntax.  Experimenting shows that it
_does_ accept a syntax where the attributes appear immediately before
the function name (at least for functions with return values not of a
pointer type).

I think it would be useful to accept the `obvious' syntax (e.g., u.c
in my transcript below).  I also think the syntax which is accepted
should be specified; in particular, the locations where the
__attribute__ may appear should be specified.

Thanks,
Ian.

-davenant:~/junk> cat t.c
static void f(void) __attribute__((noreturn));
static void f(void) { }
-davenant:~/junk> gcc -Wall -O3 -c t.c
t.c: In function `f':
t.c:2: warning: `noreturn' function does return
-davenant:~/junk> cat u.c
static void f(void) __attribute__((noreturn)) { }
-davenant:~/junk> gcc -Wall -O3 -c u.c
u.c:1: parse error before `{'
u.c:1: warning: `f' declared `static' but never defined
-davenant:~/junk> cat v.c
static void __attribute__((noreturn)) f(void) { }
-davenant:~/junk> gcc -Wall -O3 -c v.c
v.c: In function `f':
v.c:1: warning: `noreturn' function does return
-davenant:~/junk> 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]