linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Steve Graegert" <graegerts@gmail.com>
To: Shriramana Sharma <samjnaa@gmail.com>
Cc: Linux C Programming List <linux-c-programming@vger.kernel.org>
Subject: Re: "noreturn"
Date: Sun, 29 Jul 2007 15:00:02 +0200	[thread overview]
Message-ID: <6a00c8d50707290600n9f3285bs9b942de1d778d067@mail.gmail.com> (raw)
In-Reply-To: <46AC873C.3060908@gmail.com>

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>

  reply	other threads:[~2007-07-29 13:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-29 12:25 "noreturn" Shriramana Sharma
2007-07-29 13:00 ` Steve Graegert [this message]
2007-07-30  0:07 ` "noreturn" Glynn Clements

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6a00c8d50707290600n9f3285bs9b942de1d778d067@mail.gmail.com \
    --to=graegerts@gmail.com \
    --cc=linux-c-programming@vger.kernel.org \
    --cc=samjnaa@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).