comp.lang.ada
 help / color / mirror / Atom feed
From: stt@houdini.camb.inmet.com (Tucker Taft)
Subject: Re: Which compiler is right ?
Date: 1997/07/25
Date: 1997-07-25T00:00:00+00:00	[thread overview]
Message-ID: <EDvsvw.I5u.0.-s@inmet.camb.inmet.com> (raw)
In-Reply-To: 33D718BA.1E9A@magic.fr


Strategies (strategies@magic.fr) wrote:

: Hello
: Is the following code legal ?

No.

: I have two compilers with two different answers

The one that rejects the program is correct.

: generic
:    type Element_Type is limited private;
:    type Index_Type is (<>);
:    type Element_Array is array (Index_Type range <>) of Element_Type;
:    with function Equal (Left, Right : Element_Type) 
: 	return Boolean is "=";   

When you give a default for a function like this (is "="), it is looked
up when the generic is compiled, as opposed to when it is instantiated.
And there is no "=" visible that matches the given parameter profile.

The only way to specify a default that is looked up when a generic
is instantiated is to use "is <>", and then the name of the formal
subprogram must match the name that you want looked up at the point
of instantiation.  Hence, you could do the following:

    with function "="(Left, Right : Element_Type) return Boolean is <>;

Now when you instantiate this generic, if the actual parameter is omitted
for this formal parameter, then the compiler will look for a directly
visible "=" that matches the given profile.

If you prefer to use the name "Equal" inside the generic, 
you could add a remame inside the generic body, such as:

    function Equal(Left, Right : Element_Type) return Boolean renames "=";

By the way, I agree with the other responder that when you have
a question like this, it sure makes it easier to help if you include
the error messages produced by the compiler(s) with your question.

: function Generic_Indice (Left  :
: Element_Type;                          			 Right : Element_Array) return
: Index_Type;
: -- 
: ------------------------------------------------------------------------
: -- Jerome HAGUET, Strategies, Rungis, France 			      --
: -- Tel : (33 1 | 01) 41 73 04 80  ;   Fax : (33 1 | 01) 41 73 04 99   --
: -- Internet : strategies@magic.fr ;   Compuserve : 100747,2001        --
: ------------------------------------------------------------------------

-Tucker Taft   stt@inmet.com   http://www.inmet.com/~stt/
Intermetrics, Inc.  Burlington, MA  USA




  parent reply	other threads:[~1997-07-25  0:00 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-07-24  0:00 Which compiler is right ? Strategies
1997-07-25  0:00 ` Albert K. Lee
1997-07-25  0:00 ` Tucker Taft [this message]
  -- strict thread matches above, loose matches on Subject: below --
2004-03-16 13:44 which compiler is right? Lionel.DRAGHI
2004-03-16 14:56 ` Dmitry A. Kazakov
2004-03-16 23:43 ` Randy Brukardt
2004-03-17 17:27 ` Adam Beneschan
2004-03-18  5:07   ` Randy Brukardt
2004-03-18 20:33     ` Adam Beneschan
2004-03-19 19:48       ` Randy Brukardt
2004-03-16 15:35 Lionel.DRAGHI
2004-03-17 10:16 Lionel.DRAGHI
2004-03-17 17:48 ` Randy Brukardt
2004-03-17 18:53 Lionel.DRAGHI
2004-03-18  4:57 ` Randy Brukardt
2004-03-17 18:56 Lionel.DRAGHI
replies disabled

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