* "noreturn"
@ 2007-07-29 12:25 Shriramana Sharma
2007-07-29 13:00 ` "noreturn" Steve Graegert
2007-07-30 0:07 ` "noreturn" Glynn Clements
0 siblings, 2 replies; 3+ messages in thread
From: Shriramana Sharma @ 2007-07-29 12:25 UTC (permalink / raw)
To: Linux C Programming List
man:gcc at -Wunitialized says:
Some spurious warnings can be avoided if you declare all the functions
you use that never return as noreturn.
Google says this term is used only in Microsoft C++. So what is it doing
in GCC's page?
Shriramana Sharma.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: "noreturn"
2007-07-29 12:25 "noreturn" Shriramana Sharma
@ 2007-07-29 13:00 ` Steve Graegert
2007-07-30 0:07 ` "noreturn" Glynn Clements
1 sibling, 0 replies; 3+ messages in thread
From: Steve Graegert @ 2007-07-29 13:00 UTC (permalink / raw)
To: Shriramana Sharma; +Cc: Linux C Programming List
Shriramana,
On 7/29/07, Shriramana Sharma <samjnaa@gmail.com> wrote:
> man:gcc at -Wunitialized says:
>
> Some spurious warnings can be avoided if you declare all the functions
> you use that never return as noreturn.
>
> Google says this term is used only in Microsoft C++. So what is it doing
> in GCC's page?
What do you mean by that? There is no indication that
__attribute__((noreturn)) is _only_ used within the Microsoft
environment.
Some standard library functions, such as abort(3) and exit(3), cannot
return. GCC is able to determine this fact automatically. When you
define your own functions that never return you can declare them
noreturn to tell the compiler about it. For example,
void doesnotreturn(void) __attribute__ ((noreturn));
void doesnotreturn (void) {
/* do some work here */
exit (1);
}
Telling the compiler to assume that doesnotreturn() cannot return
allows for gcc to optimize code without regard to what would happen if
doesnotreturn actucally returns.
What exactly is not clear about the usage of noreturn? The gcc manual
also makes clear that even semantically correct code can cause an
unitialized warning since
"GNU CC is not smart enough to see all the reasons why the code might
be correct despite appearing to have an error."
\Steve
--
Steve Graegert <steve@graegert.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: "noreturn"
2007-07-29 12:25 "noreturn" Shriramana Sharma
2007-07-29 13:00 ` "noreturn" Steve Graegert
@ 2007-07-30 0:07 ` Glynn Clements
1 sibling, 0 replies; 3+ messages in thread
From: Glynn Clements @ 2007-07-30 0:07 UTC (permalink / raw)
To: Shriramana Sharma; +Cc: Linux C Programming List
Shriramana Sharma wrote:
> man:gcc at -Wunitialized says:
>
> Some spurious warnings can be avoided if you declare all the functions
> you use that never return as noreturn.
>
> Google says this term is used only in Microsoft C++.
Wrong.
> So what is it doing in GCC's page?
The "noreturn" attribute is the first one in the "Function Attributes"
page of the gcc Info file:
`noreturn'
A few standard library functions, such as `abort' and `exit',
cannot return. GCC knows this automatically. Some programs define
their own functions that never return. You can declare them
`noreturn' to tell the compiler this fact. For example,
void fatal () __attribute__ ((noreturn));
void
fatal (/* ... */)
{
/* ... */ /* Print error message. */ /* ... */
exit (1);
}
The `noreturn' keyword tells the compiler to assume that `fatal'
cannot return. It can then optimize without regard to what would
happen if `fatal' ever did return. This makes slightly better
code. More importantly, it helps avoid spurious warnings of
uninitialized variables.
Do not assume that registers saved by the calling function are
restored before calling the `noreturn' function.
It does not make sense for a `noreturn' function to have a return
type other than `void'.
The attribute `noreturn' is not implemented in GCC versions
earlier than 2.5. An alternative way to declare that a function
does not return, which works in the current version and in some
older versions, is as follows:
typedef void voidfn ();
volatile voidfn fatal;
--
Glynn Clements <glynn@gclements.plus.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2007-07-30 0:07 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-29 12:25 "noreturn" Shriramana Sharma
2007-07-29 13:00 ` "noreturn" Steve Graegert
2007-07-30 0:07 ` "noreturn" Glynn Clements
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).