This is the mail archive of the gcc-help@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]
Other format: [Raw text]

what's the point of a return type with "__attribute__((noreturn))"?


  at the moment, we're having an animated discussion over at the linux
kernel mailing list regarding proper usage of attributes, so i'd like
to ask a few questions about how people tend to use them.  as
examples, let's say i wanted to tag a function as deprecated.

  first, i'm assuming that the function declaration (if there is one)
can be written as any one of:

__attribute__((deprecated)) int fubar(void);
int __attribute__((deprecated)) fubar(void);
int fubar(void) __attribute__((deprecated));

  that is, the attribute placement in the declaration is flexible,
even though it appears that that last form seems to be the most
popular, is that right?

  next, once i set an attribute on a function *declaration*, there's
no need to also set it on the subsequent function *definition*.  i
mean, i *could* but that would be redundant, correct?  however, in the
case where there is *only* a function definition, i could write that
definition in one of two ways:

__attribute__((deprecated)) int fubar(void) { ... }
int __attribute__((deprecated)) fubar(void) { ... }

  and, again, that second form seems to be more popular.  so far, so
good?  (just to clarify this in my mind, most of the declarations i've
seen have the attribute at the end, while most definitions put the
attribute between the return type and the routine name.)

  the big issue, though, involves "__attribute__((noreturn))".
the gcc manual on this page:

http://www.delorie.com/gnu/docs/gcc/gcc_55.html

shows the following snippet of code:

...
void fatal () __attribute__ ((noreturn));

void
fatal (...)
{
  ... /* Print error message. */ ...
  exit (1);
}
...

to keep a long question short, even though a "noreturn" routine
doesn't return, is it still traditional to declare it with a return
type of "void"?  thanks.

rday
-- 
========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA

http://fsdev.net/wiki/index.php?title=Main_Page
========================================================================


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