[net.lang.ada] Ambiguous use of dereference in Ada

rosen@gypsy.UUCP (07/22/85)

I have noted an unusually item while writting some Ada code.  This strange
item involved the dereference operator 'all' for use with access types.  See
the following piece of code:

--------------------------------------------------------------
  procedure weird_ptrs is

     type stupid is 
       record
	 a: integer;
	 b: float;
       end record;

     type stupid_ptr is access stupid;

     c1, c2: integer;
     xxx: stupid_ptr;

  begin
        xxx := new stupid'(a => 100, b => 3.1415);
        c1 := xxx.a;		--1--
        c2 := xxx.all.a;	--2--

  end weird_ptrs;
---------------------------------------------------------------------------


The compiler (Verdix 4.02) does not complain about lines --1-- and --2--.
Actually they appear to be exactly the same.   In --1-- the dereference
operation is implicit while in --2-- the deference operation is performed
through the 'all' operator.  I find this to be extremely strange even
thought I can accept both methods.  What bothers me is that the LRM is very
vague about mentioning any difference between these two methods.  This
certainly can be very confusing when reading code.  Does anybody have any
thoughts on why this is?  I don't believe it is a bug, but please let me
know if there is a compiler that has something to say about this.


Steve Rosen
Siemens Research and Technology Laboratories
Princeton, NJ

USENET: {ihnp4|princeton|adrvax}!siemens!rosen
ARPA:   princeton!siemens!rosen@TOPAZ

joe@petsd.UUCP (Joe Orost) (07/24/85)

In article <38000019@gypsy.UUCP> rosen@gypsy.UUCP writes:
>     ...
>     type stupid is 
>       record
>	 a: integer;
>	 b: float;
>       end record;
>     type stupid_ptr is access stupid;
>     c1, c2: integer;
>     xxx: stupid_ptr;
>  begin
>        c1 := xxx.a;		--1--
>        c2 := xxx.all.a;	--2--
>     ...

Some quotes from the bible:

	4.1.3(6)     (b) A component of a record:

	     (7)	The selector must be a simple name denoting a
			component of a record object or value.  The prefix
			must be APPROPRIATE FOR THE TYPE of this object or
			value.

	     (11)    (d) An object designated by an access value:

	     (12)	The selector must be the reserved word ALL.  The
			value of the prefix must belong to an access type.

	4.1(6)		A prefix is said to be APPROPRIATE FOR A TYPE in
			either of the following cases:

	   (7)		 o The type of the prefix is the type considered.

	   (8)		 o The type of the prefix is an access type whose
			   designated type is the type considered.

In your example, the first dereference is legal because of 4.1.3(7) & 4.1(8).
The second dereference is legal because of 4.1.3(12) & 4.1.3(7) & 4.1(7).

QED.

				regards,
				joe

--

 ........        .........	Full-Name:  Joseph M. Orost
 .       .       .		UUCP:       ihnp4!vax135!petsd!joe
 . ......   ...  ........	ARPA:	    vax135!petsd!joe@BERKELEY
 .               .		Phone:      (201) 758-7284
 .               .........	Location:   40 19'49" N / 74 04'37" W
				US Mail:    MS 313; Perkin-Elmer; 106 Apple St
					    Tinton Falls, NJ 07724