From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: * X-Spam-Status: No, score=1.3 required=5.0 tests=BAYES_00,INVALID_MSGID, MSGID_RANDY autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,dabd2d2ffbcf1daa X-Google-Attributes: gid103376,public From: Robert Dewar Subject: Re: Exiting from a function or procedure Date: 2000/04/23 Message-ID: <8duvlj$opk$1@nnrp1.deja.com>#1/1 X-Deja-AN: 614616786 References: <8ds3qe$q2d$1@nnrp1.deja.com> X-Http-Proxy: 1.0 x34.deja.com:80 (Squid/1.1.22) for client 166.72.69.228 Organization: Deja.com - Before you buy. X-Article-Creation-Date: Sun Apr 23 14:00:25 2000 GMT X-MyDeja-Info: XMYDJUIDrobert_dewar Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/4.61 [en] (OS/2; I) Date: 2000-04-23T00:00:00+00:00 List-Id: In article , 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.