comp.lang.ada
 help / color / mirror / Atom feed
From: ahlan@marriott.org
Subject: Re: Uninitialized out parameters.
Date: Tue, 5 Apr 2016 07:07:14 -0700 (PDT)
Date: 2016-04-05T07:07:14-07:00	[thread overview]
Message-ID: <531318fc-daf0-4f4e-bc82-2b48699f3cb5@googlegroups.com> (raw)
In-Reply-To: <4b5fb0cb-2dbd-47c1-a5e2-41d4ffcab84e@googlegroups.com>

On Tuesday, April 5, 2016 at 3:17:46 PM UTC+2, riea...@comcast.net wrote:
> On Tuesday, April 5, 2016 at 8:02:51 AM UTC-4, ah...@marriott.org wrote:
> > Hi,
> > 
> > Is this a GNAT (GPL-2015) bug or my not understanding Ada?
> > 
> > I was surprised that I could compile
> >   procedure Test (V : out Positive) is null;
> > 
> > and even more by the results of calling the procedure 
> > 
> >   V : Positive;
> > begin
> >   Test (V);
> >   Ada.Text_IO.Put_Line ("V:" & V'img);
> > 
> > The value zero is output, which because V is positive should be impossible.
> > 
> > I would have thought that null procedures with out parameters would fail to compile. 
> > 
> > Opinions anyone?
> > 
> > MfG
> > Ahlan
> 
> There are two issues here. One is whether this program is 'legal' Ada.  Short answer, there are many, many more Ada programs than Ada programs that "make sense."  This is just another example.  The second issue?  Are compilers allowed to warn you about this code?  Sure.  But why allow it?  Right now I am working on a generic package where GNAT warns me that some of the code in an instantiation will Constraint_Error if executed. But it can only be reached if the generic is instantiated with a generic formal such that the code will not raise an error.  I'll add pragma Suppress (Index_Check) before I'm done, but for now, if a fifth warning shows up, I'll know to be concerned. ;-)
> 
> Is it possible to write code which will only raise an error if Fermat's Last Theorem is false?  Sure, I've done it.  I did it just to show that a proposal for elaboration order checking was flawed.  The ARG navigates a fine line between allowing all useful programs to be written, and requiring compilers to do tons of checks for unintended errors.  Look for example at 6.5.1 Nonreturning procedures.
> 
> Is it meaningful for a nonreturning procedure to set an out parameter?  Should a compiler be required to make that check? (Either for or against.)  The answer is that Ada is used in many contexts where nonreturning procedures are meaningful--I normally did so in flight guidance software.  For manned aircraft you certainly want to be sure that the main processing loop never exits while power is on.  But the intersection of a parameter check and nonreturning procedures (whatever you would expect that check to do) is just making unnecessary work for the compiler.  Similarly a procedure may be called with an out parameter that already has a value.  So it is the programmer's job to deal with the union of these issues in a sensible way.
> 
> Could GNAT (or any other) compiler provide a warning?  Sure, and it does:
> 
> procedure NoSet is
>   Counter: Positive;
>   procedure Reset (V : out Positive;
>                    User_Check: Boolean := True) is
>     function Ask_User return Boolean is begin return True; end; -- TBD
>   begin
>     if User_Check and then Ask_User then return; end if;
>     V := 1;
>   end Reset;
> begin
>   Reset(Counter);
> end NoSet;
> 
> gnatmake -O3 noset.adb
> gcc -c -O3 noset.adb
> noset.adb:7:42: warning: "out" parameter "V" not set before return
> gnatbind -x noset.ali
> gnatlink noset.ali -O3
> 
> Compilation finished at Tue Apr 05 09:13:54

Hi,
You write
"Could GNAT (or any other) compiler provide a warning?  Sure, and it does: "
but that's my whole point - GNAT doesn't in my example.
And I feel that it should.
A null procedure is NOT a non-returning procedure - it does return and moreover in my example actually returns an illegal value!

In my gpr I compile with
   package Compiler is
      for Default_Switches ("ada") use ("-O1", "-gnatQ", "-gnato", "-g", "-gnat12",
                                        "-gnatwcehijkmopruvz.c.n.p.t.w.x", "-gnatykmpM120");
   end Compiler;

Is there a warning that I need to explicitly switch on in order that GNAT checks for out parameters in  null procedures?

MfG
Ahlan


  reply	other threads:[~2016-04-05 14:07 UTC|newest]

Thread overview: 91+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-05 12:02 Uninitialized out parameters ahlan
2016-04-05 13:17 ` rieachus
2016-04-05 14:07   ` ahlan [this message]
2016-04-06  9:45     ` Mark Lorenzen
2016-04-06 21:01       ` Jeffrey R. Carter
2016-04-07  7:10       ` ahlan
2016-04-05 16:19 ` G.B.
2016-04-06  8:19   ` ahlan
2016-04-06 10:17     ` G.B.
2016-04-06 11:44       ` Dennis Lee Bieber
2016-04-06 20:41         ` Niklas Holsti
2016-04-06 20:54         ` Randy Brukardt
2016-04-06 20:47       ` Randy Brukardt
2016-04-06 21:01         ` Randy Brukardt
2016-04-06 21:22           ` Dmitry A. Kazakov
2016-04-07  7:27             ` Randy Brukardt
2016-04-06 11:37 ` AdaMagica
2016-04-06 13:44   ` ahlan
2016-04-06 14:09     ` Mark Lorenzen
2016-04-06 14:10     ` G.B.
2016-04-06 20:53     ` Stefan.Lucks
2016-04-06 21:03       ` Randy Brukardt
2016-04-06 21:12       ` Niklas Holsti
2016-04-06 21:30       ` Randy Brukardt
2016-04-07  9:56         ` Stefan.Lucks
2016-04-07 16:08           ` AdaMagica
2016-04-07 23:02             ` Randy Brukardt
2016-04-08  7:32               ` Dmitry A. Kazakov
2016-04-07  7:52       ` Georg Bauhaus
  -- strict thread matches above, loose matches on Subject: below --
1996-07-29  0:00 W. Wesley Groleau (Wes)
1996-07-18  0:00 Uninitialized "out" parameters Paul Whittington
1996-07-18  0:00 ` Robert Dewar
1996-07-19  0:00   ` Peter Amey
1996-07-20  0:00   ` Fergus Henderson
1996-07-20  0:00     ` Robert Dewar
1996-07-21  0:00       ` Fergus Henderson
1996-07-21  0:00         ` Robert Dewar
1996-07-23  0:00           ` Fergus Henderson
1996-07-23  0:00             ` Robert A Duff
1996-07-24  0:00               ` Fergus Henderson
1996-07-24  0:00               ` Fergus Henderson
1996-07-23  0:00           ` Richard A. O'Keefe
1996-07-23  0:00             ` Robert A Duff
1996-07-24  0:00               ` Richard A. O'Keefe
1996-07-24  0:00                 ` Robert A Duff
1996-07-25  0:00                   ` Richard A. O'Keefe
1996-07-25  0:00                     ` Robert A Duff
1996-07-24  0:00                 ` Theodore E. Dennison
1996-07-25  0:00                 ` Frank Manning
1996-07-25  0:00                   ` Richard A. O'Keefe
1996-07-26  0:00                     ` Frank Manning
1996-07-23  0:00             ` Robert Dewar
1996-07-24  0:00               ` Fergus Henderson
1996-07-24  0:00               ` Robert A Duff
1996-07-24  0:00               ` Fergus Henderson
1996-07-25  0:00               ` Richard A. O'Keefe
1996-07-25  0:00                 ` Robert A Duff
1996-07-18  0:00 ` Adam Beneschan
1996-07-18  0:00   ` Robert Dewar
1996-07-19  0:00   ` Dale Stanbrough
1996-07-19  0:00     ` Adam Beneschan
1996-07-19  0:00     ` James A. Squire
1996-07-19  0:00       ` Adam Beneschan
1996-07-20  0:00       ` Michael Feldman
1996-07-21  0:00         ` Fergus Henderson
1996-07-21  0:00           ` Michael Feldman
1996-07-21  0:00             ` Robert Dewar
1996-07-22  0:00             ` Fergus Henderson
1996-07-23  0:00               ` Michael Feldman
1996-07-23  0:00                 ` Robert Dewar
1996-07-25  0:00                   ` Fergus Henderson
1996-07-24  0:00                 ` Fergus Henderson
1996-07-24  0:00                 ` Robert A Duff
1996-07-25  0:00                   ` Richard A. O'Keefe
1996-07-19  0:00   ` Samuel Tardieu
1996-07-19  0:00     ` John Herro
1996-07-19  0:00       ` Tucker Taft
1996-07-23  0:00         ` Peter Hermann
1996-07-23  0:00           ` Robert A Duff
1996-07-19  0:00   ` Pascal Obry
1996-07-19  0:00     ` Peter Hermann
1996-07-19  0:00 ` Peter Amey
1996-07-19  0:00 ` Michel Gauthier
1996-07-21  0:00   ` Robert A Duff
1996-07-21  0:00 ` Robert A Duff
1996-07-23  0:00 ` John Herro
1996-07-23  0:00   ` Robert Dewar
1996-07-24  0:00     ` Peter Hermann
1996-07-23  0:00   ` Robert A Duff
1996-07-26  0:00   ` Stephen J Bevan
1996-07-26  0:00     ` Robert A Duff
replies disabled

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