comp.lang.ada
 help / color / mirror / Atom feed
From: Robert Dewar <dewar@gnat.com>
Subject: Re: Exiting from a function or procedure
Date: 2000/04/23
Date: 2000-04-23T00:00:00+00:00	[thread overview]
Message-ID: <8duvlj$opk$1@nnrp1.deja.com> (raw)
In-Reply-To: BKmM4.214$nb6.208368@news.pacbell.net

In article <BKmM4.214$nb6.208368@news.pacbell.net>,
  tmoran@bix.com wrote:
> > So NEVER EVER ignore warnings, consider them as errors.  In
> > fact you might want to use -gnatwe so the compiler will
> > treat them as errors enforcing this discipline.
>
> This is not always a good idea.  For instance
>      if OK then
>        return some_value;
>      else
>        Log_And_Raise_Error;
>      end if;
>    end some_function;
> is a perfectly legitimate paradigm in Ada that would become
> illegal in Gnat with -gnatwe, since the compiler doesn't know
> that Log_And_Raise_Error will never return.


Two responses:

I still prefer to work with -gnatwe, and then use pragma
Warnings (Off) to locally suppress a warning that can be
ignored, always adding a comment as to why this is being done.

Second, in this particular case, that is exactly why we added
the pragma No_Return to GNAT. When using GNAT, if you have
a procedure like Log_And_Raise_Error, then you declare that
procedure with pragma No_Return, and two things happen, first
the compiler checks that there are no return statements in
Log_And_Raise_Error, second the warning is suppressed at the
point of call.

The trouble with leaving warnings in your code is that you can
easily get into the habit of ignoring warnings, and we see many
people generating lots of extra work for themselves this way.
GNAT goes to a considerable effort to generate all kinds of
useful warnings -- we often get the reaction when people port
to GNAT from another compiler that they discover latent bugs
in their code from these warnings.

So getting into the habit of never ignoring warnings and
insisting on warning-free code is a good one, and I repeat
my advice to follow this approach. Using -gnatwe (as we do
when we compile GNAT) is a good way to enforce this discipline.

Of course the pragmas Warnings (Off) and No_Return are GNAT
specific, but there are several points to be made there:

1. Unrecognized pragmas are ignored, it is VERY unlikely that
any other compiler recognizes these pragmas unless it implements
them.

2. Warnings are pretty compiler dependent anyway, GNAT tends to
be pretty aggressive in looking for opportunities to generate
warnings. Note that some compilers don't even generate warnings
at all for missing blocked return paths in functions.

3. In several cases, pragmas initially introduced into GNAT are
being considered for more general adoption (pragma Unsuppress is
an example). Perhaps pragma Warnings (Off) and No_Return are
other candidates.

Robert Dewar
Ada Core Technologies


Sent via Deja.com http://www.deja.com/
Before you buy.




  parent reply	other threads:[~2000-04-23  0:00 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-04-21  0:00 Exiting from a function or procedure Andres Tarallo
2000-04-21  0:00 ` Robert A Duff
2000-04-21  0:00 ` tmoran
2000-04-21  0:00   ` Andres Tarallo
2000-04-22  0:00     ` Robert Dewar
2000-04-22  0:00       ` Ken Garlington
2000-04-22  0:00       ` tmoran
2000-04-22  0:00         ` Ray Blaak
2000-04-22  0:00           ` David Starner
2000-04-23  0:00         ` Robert Dewar [this message]
2000-04-23  0:00           ` tmoran
2000-04-24  0:00             ` Robert Dewar
2000-04-24  0:00               ` tmoran
2000-04-24  0:00                 ` Robert Dewar
2000-04-24  0:00             ` Robert Dewar
2000-04-22  0:00       ` Pablo Moisset
2000-04-23  0:00         ` Robert Dewar
2000-04-24  0:00       ` Scott Ingram
2000-04-22  0:00   ` Robert Dewar
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox