comp.lang.ada
 help / color / mirror / Atom feed
* Array type conversion
@ 2002-10-18  4:43 Keith
  2002-10-18  6:55 ` Jean-Pierre Rosen
  2002-10-18 14:59 ` Robert A Duff
  0 siblings, 2 replies; 5+ messages in thread
From: Keith @ 2002-10-18  4:43 UTC (permalink / raw)


What is the implementation consequence of not following  Ada reference
manual section 4.6 12/1 "The component subtypes shall statically match"?

What was the rational behind not allowing something like the following:

type some_type is new integer;
type A is array ( index_type) of integer;
type B is array ( index_type) of some_type;
Array_A:A;
Array_B:B;


declare

begin
    Array_A:=A( Array_B);

end;

Rather than the legal but more cumbersome

   for Index in index_type'range loop
      Array_A(Index):=A(Array_B(Index));
   end loop;

I know that if the component subtypes have to statically match in an array
conversion then  there is no need to check for matching constraints at run
time like Ada 83. Does this speed up execution?

But
Array_A:=A( Array_B);

seems more inline with the spirit of Ada Array operations like A+B etc.
Thanks
--
Keith






^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Array type conversion
  2002-10-18  4:43 Array type conversion Keith
@ 2002-10-18  6:55 ` Jean-Pierre Rosen
  2002-10-18 15:15   ` Robert A Duff
  2002-10-19  3:27   ` Keith
  2002-10-18 14:59 ` Robert A Duff
  1 sibling, 2 replies; 5+ messages in thread
From: Jean-Pierre Rosen @ 2002-10-18  6:55 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1177 bytes --]


"Keith" <nono@joimail.net> a �crit dans le message news:
aoo3h9$s7u$1@news.chatlink.com...
> What is the implementation consequence of not following  Ada reference
> manual section 4.6 12/1 "The component subtypes shall statically match"?
>
> What was the rational behind not allowing something like the following:
>
> type some_type is new integer;
> type A is array ( index_type) of integer;
> type B is array ( index_type) of some_type;
> Array_A:A;
> Array_B:B;
>
>
> declare
>
> begin
>     Array_A:=A( Array_B);
>
> end;
>
> Rather than the legal but more cumbersome
>
>    for Index in index_type'range loop
>       Array_A(Index):=A(Array_B(Index));
>    end loop;
>
A derived type needs not have the same representation as its ancestor type.
If the subtypes statically match, the compiler can perform a simple memory
copy. Otherwise, the compiler must in effect generate the exact equivalent
of the loop you give, and there is a deliberate decision in Ada to avoid, as
far as possible, *hidden* inefficiencies.

--
---------------------------------------------------------
           J-P. Rosen (rosen@adalog.fr)
Visit Adalog's web site at http://www.adalog.fr





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Array type conversion
  2002-10-18  4:43 Array type conversion Keith
  2002-10-18  6:55 ` Jean-Pierre Rosen
@ 2002-10-18 14:59 ` Robert A Duff
  1 sibling, 0 replies; 5+ messages in thread
From: Robert A Duff @ 2002-10-18 14:59 UTC (permalink / raw)


"Keith" <nono@joimail.net> writes:

> What is the implementation consequence of not following  Ada reference
> manual section 4.6 12/1 "The component subtypes shall statically match"?
...
> I know that if the component subtypes have to statically match in an array
> conversion then  there is no need to check for matching constraints at run
> time like Ada 83. Does this speed up execution?

Yeah, but I think the main reason was to catch bugs at compile time
rather than run time.  There are several similar cases in Ada 95,
where a run-time check in Ada 83 was changed to a static check in Ada
95.

There might have been some other issue related to passing type
conversions as 'out' parameters, especially when the type is limited,
so the conversion cannot be implemented by copying.  I'm not sure
about that, and I don't feel like thinking about it right now.  ;-)

- Bob



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Array type conversion
  2002-10-18  6:55 ` Jean-Pierre Rosen
@ 2002-10-18 15:15   ` Robert A Duff
  2002-10-19  3:27   ` Keith
  1 sibling, 0 replies; 5+ messages in thread
From: Robert A Duff @ 2002-10-18 15:15 UTC (permalink / raw)


"Jean-Pierre Rosen" <rosen@adalog.fr> writes:

> A derived type needs not have the same representation as its ancestor type.
> If the subtypes statically match, the compiler can perform a simple memory
> copy.

Hmm.  I don't think that's right.  Even if the two array types have
identical component subtypes, one could have pragma Pack, and the other
not, which would require component-by-component copying.  Similarly, one
could have a different 'Component_Size specified.

>... Otherwise, the compiler must in effect generate the exact equivalent
> of the loop you give, and there is a deliberate decision in Ada to avoid, as
> far as possible, *hidden* inefficiencies.

That principle is often stated in the Ada world.  IMHO, it is not a good
principle of language design, and in fact Ada disobeys it more often
than it obeys.  And the cases where it disobeys are cleaner.

- Bob



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Array type conversion
  2002-10-18  6:55 ` Jean-Pierre Rosen
  2002-10-18 15:15   ` Robert A Duff
@ 2002-10-19  3:27   ` Keith
  1 sibling, 0 replies; 5+ messages in thread
From: Keith @ 2002-10-19  3:27 UTC (permalink / raw)


But generating the code to do a simple copy versus a more complex conversion
based upon whether the subtype representations are the same or not does not
seem to be much of an inefficiency.

"> A derived type needs not have the same representation as its ancestor
type.
> If the subtypes statically match, the compiler can perform a simple memory
> copy. Otherwise, the compiler must in effect generate the exact equivalent
> of the loop you give, and there is a deliberate decision in Ada to avoid,
as
> far as possible, *hidden* inefficiencies.
>
> --
> ---------------------------------------------------------
>            J-P. Rosen (rosen@adalog.fr)
> Visit Adalog's web site at http://www.adalog.fr
>
>





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2002-10-19  3:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-18  4:43 Array type conversion Keith
2002-10-18  6:55 ` Jean-Pierre Rosen
2002-10-18 15:15   ` Robert A Duff
2002-10-19  3:27   ` Keith
2002-10-18 14:59 ` Robert A Duff

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