Re: "noreturn"

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Shriramana,

On 7/29/07, Shriramana Sharma <samjnaa@xxxxxxxxx> 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@xxxxxxxxxxxx>
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Assembler]     [Git]     [Kernel List]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [C Programming]     [Yosemite Campsites]     [Yosemite News]     [GCC Help]

  Powered by Linux