comp.lang.ada
 help / color / mirror / Atom feed
* Pragma Import on arrays in record types
@ 2002-11-05  7:13 Sebastian
  0 siblings, 0 replies; 2+ messages in thread
From: Sebastian @ 2002-11-05  7:13 UTC (permalink / raw)


Hi,

Why do I get a compiler warning when I do an overlaid storage of a record
type consisting
of an array? See below.

When I use pragma Import on the object it works fine but what is the
compiler doing?

/S
with Interfaces; use Interfaces;

with Ada.Text_Io; use Ada.Text_Io;



procedure Array_Test is

type Flag_Type is (Reset, Set);

for Flag_Type'Size use 1;


------------------------------------------------------------------------

package Enum is new ada.text_io.enumeration_Io(Flag_Type);

use Enum;


------------------------------------------------------------------------

type Index_Type is (

Index_0, Index_1,  Index_2, Index_3,

Index_4, Index_5, Index_6, Index_7,

Index_8, Index_9, Index_10, Index_11,

Index_12, Index_13, Index_14, Index_15);

for Index_Type'Size use 16;


type Array_Of_Index_Type is array (Index_Type) of Flag_Type;


pragma pack(Array_Of_Index_Type);


------------------------------------------------------------------------

type Record_Type is

record

Gp_Flag_Command : Array_Of_Index_Type;

end record;


for Record_Type use

record

Gp_Flag_Command at 0 range 0 ..15;

end record;

pragma Volatile(Record_Type);


------------------------------------------------------------------------

Record_1 : Record_Type;

Record_2 : Record_Type;

-- pragma import(Ada, Device_2);


for Record_2'Address use Record_1'Address;


begin


null;

end Array_Test;






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

* Re: Pragma Import on arrays in record types
@ 2002-11-05  7:35 Grein, Christoph
  0 siblings, 0 replies; 2+ messages in thread
From: Grein, Christoph @ 2002-11-05  7:35 UTC (permalink / raw)


> Record_1 : Record_Type;
> Record_2 : Record_Type;
> 
> -- pragma import(Ada, Device_2);   <-- Record_2 I presume?
> 
> for Record_2'Address use Record_1'Address;

You do not say which error message you get. But fact is that the last staement 
above is not required to be accepted by the RM. You should instead write:

Record_1_Address: constant System.Address := Record_1'Address;
for Record_2'Address use Record_1_Address;

This looks nearly the same (in fact you'll ask where the difference is), but 
this has to be accepted according to the RM.

To quote Robert Dewar:

  The big difference is that the first form is not reqiured to be accepted by
  the RM, and the second form is required to be accepted. The first form can
  lead to circularities, the most obvious being:

     X, Y : Integer;
     for X'Address use Y'Address;
     for Y'Address use X'Address;

  The second form with constant, the form required to be accepted by the RM,
  can never lead to such circularities. The discussion in the AARM further
  discusses why the RM restriction is there.

Pragma Import should be used with overlays to prevent initialization.

But why the heck do you want to overlay two objects of the same type?
A renaming statement seems more appropriate in this case.

Pragmas Import and Export are hideous in that they allow to undermine the Ada 
type concept.



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

end of thread, other threads:[~2002-11-05  7:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-11-05  7:35 Pragma Import on arrays in record types Grein, Christoph
  -- strict thread matches above, loose matches on Subject: below --
2002-11-05  7:13 Sebastian

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