comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@world.std.com>
Subject: Re: Return by reference
Date: 1999/11/02
Date: 1999-11-02T00:00:00+00:00	[thread overview]
Message-ID: <wccg0yoyff3.fsf@world.std.com> (raw)
In-Reply-To: Pine.BSF.4.10.9911011705320.5772-100000@shell5.ba.best.com

Brian Rogoff <bpr@shell5.ba.best.com> writes:

> I understand why, for a return-by-reference type T, the function 
> 
> function Some_Func( ... ) return T is 
>     Local_Var : T
> begin
>     ...
>     return Local_Var;
> end Some_Func;
> 
> causes Program_Error to be raised at run time, but I'm a bit 
> perplexed as to why there is a problem for 
> 
> function Some_Func( Param : T; ... ) return T is
> begin
>     ...
>     return Param;
> end Some_Func;
> 
> Could someone explain why the latter case is problematic? 

We wanted the checks to be done at compile time.

So you may well ask, why does this one raise Program_Error?  It's
because in a shared-body generic, we don't know enough to do the check
at compile time.  However, most compilers use macro-expanded generics,
so they can check the above at compile time, and just generate code to
raise P_E if the check fails, and, one hopes, give a message at compile
time.

If the above were allowed, then somebody could do this:

    function Mumble return T is
        Local: T;
    begin
        return Some_Func(Local); -- Wrong.
    end Mumble;

To detect that error would require keeping too much dope around at run
time.

On the other hand, if you want true run-time checks, you can use access
parameters.  Some extra dope is normally passed with an access
parameter.

- Bob




  reply	other threads:[~1999-11-02  0:00 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-11-01  0:00 Return by reference Brian Rogoff
1999-11-02  0:00 ` Robert A Duff [this message]
1999-11-02  0:00   ` Brian Rogoff
1999-11-03  0:00     ` Lutz Donnerhacke
1999-11-03  0:00       ` Brian Rogoff
1999-11-04  0:00         ` Lutz Donnerhacke
1999-11-06  0:00           ` Brian Rogoff
1999-11-07  0:00             ` Lutz Donnerhacke
1999-11-04  0:00       ` Robert A Duff
1999-11-03  0:00     ` Matthew Heaney
1999-11-03  0:00       ` Matthew Heaney
1999-11-03  0:00       ` Brian Rogoff
1999-11-02  0:00 ` Lutz Donnerhacke
  -- strict thread matches above, loose matches on Subject: below --
2017-12-17 14:38 Jere
2017-12-17 14:57 ` Dmitry A. Kazakov
2017-12-18  0:51   ` Mehdi Saada
2017-12-18  8:18     ` Dmitry A. Kazakov
2017-12-18 10:47       ` Mehdi Saada
2017-12-18 12:16         ` Dmitry A. Kazakov
2017-12-18 22:41     ` Randy Brukardt
2017-12-18 22:33 ` Randy Brukardt
2017-12-19  1:29   ` Jere
replies disabled

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