comp.lang.ada
 help / color / mirror / Atom feed
From: Leif Holmgren <nobody@nowhere.com>
Subject: Re: Ada style of passing 'in' parameters considered dangerous?
Date: Mon, 10 Feb 2003 01:13:30 +0100
Date: 2003-02-10T01:13:30+01:00	[thread overview]
Message-ID: <I8C1a.609$Ni6.499@nntpserver.swip.net> (raw)
In-Reply-To: 86isvuzabx.fsf@hoastest1-8c.hoasnet.inet.fi

Antti Sykari wrote:
> 
> Hello,
Hi!

> - Have you encountered a non-trivial real-life case where the
>   programmer has shot himself in the foot in the form of
>   implementation-defined behavior because of the error mentioned
>   above?
Yes.

Not exactly due to aliasing but due to exceptions. Consider the
following:

...

  procedure Calc_Routine(X : in out integer) is
  begin
    X:=X+3;
    ...
    raise Calculation_error;
  end Local;

...

  Z:=6;
  declare
    Calc_Routine(Z);
  exception
    when Calculation_Error =>
      null;
  end;
  -- Try guessing what X is.

Actually this was a bad example, and not what appeared in our code. In
reality the procedure did some things with a file whose file handle was
the input parameter. Then closed it, and finally did some other
processing. The last calculations caused an exception. After this the
calling code crashed since it believed that the file was still open.


> - If there are such cases, could it have been prevented by having
>   different policy in the language?  Do you think it would've been
>   better to force the programmer to specify the parameter passing
>   mechanism, for example?

Yes and no. We had not done our homework properly. The ARM states that
you cannot know how parameters are passed. With this knowledge you wont
do this kind of mistaktes.
The solution of this would however have been easier if we could have
added something like %ref like in the good old vax-fortran days. Now we
had to do a lot of restructuring and searching for similar code
fragments (non found).

/Leif



  parent reply	other threads:[~2003-02-10  0:13 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-08 22:24 Ada style of passing 'in' parameters considered dangerous? Antti Sykari
2003-02-09  0:41 ` James S. Rogers
2003-02-09  2:11   ` Robert A Duff
2003-02-09  2:25   ` Jeffrey Carter
2003-02-11  8:39   ` Gautier
2003-02-09  2:01 ` Robert A Duff
2003-02-09  2:33   ` Vinzent Hoefler
2003-02-09  6:07   ` Richard Riehle
2003-02-09  7:13   ` Robert I. Eachus
2003-02-10  4:40     ` Martin Dowie
2003-02-09  2:08 ` Jeffrey Carter
2003-02-10  0:13 ` Leif Holmgren [this message]
2003-02-10  9:49 ` Rod Chapman
2003-02-11  9:14 ` Gautier
2003-02-11 13:49   ` Antti Sykari
2003-02-11 17:18   ` Gautier
2003-02-11 17:29     ` Vinzent Hoefler
2003-02-12  1:09   ` Richard Riehle
replies disabled

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