comp.lang.ada
 help / color / mirror / Atom feed
* Portability questions
@ 2000-04-24  0:00 Wes Groleau
  2000-04-25  0:00 ` Robert A Duff
  0 siblings, 1 reply; 4+ messages in thread
From: Wes Groleau @ 2000-04-24  0:00 UTC (permalink / raw)



An annotation in the AARM points out that initializations
are not suppressed by address clauses.

1. Is there any place in the official RM that says that?
   (I have used the argument "it says over here that this
   happens.  It doesn't say there are any exceptions.")

2. How does this apply or not apply to initializations
   that are NOT required by the language?  For example,

   type Byte is range 0 .. 255;
   for Byte'Size use 8;

   type Buffer is array (Positive range <>) of Byte;
   pragma Pack (Buffer);

   B : Buffer (1..Length_Of_Message);
   for B'Address use Address_Of_Message;

   -- compiler A fills the space of any declared buffer with
   -- zeroes.  The language does not require this.  How does
   -- erasing the received message fit with the Ada 95 rules?

-- 
Wes Groleau
http://freepages.genealogy.rootsweb.com/~wgroleau




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

* Re: Portability questions
  2000-04-24  0:00 Portability questions Wes Groleau
@ 2000-04-25  0:00 ` Robert A Duff
  2000-04-25  0:00   ` Robert Dewar
  0 siblings, 1 reply; 4+ messages in thread
From: Robert A Duff @ 2000-04-25  0:00 UTC (permalink / raw)


Wes Groleau <wwgrol@ftw.rsc.raytheon.com> writes:

> An annotation in the AARM points out that initializations
> are not suppressed by address clauses.

Right.  If you want to avoid default initializations, use pragma Import,
in addition to the address clause.  I think Annex B says something about
that.

> 1. Is there any place in the official RM that says that?
>    (I have used the argument "it says over here that this
>    happens.  It doesn't say there are any exceptions.")

That's the right argument.

After all, how do we know that making a variable name start with Q
doesn't cause initializations to be skipped?  Because the RM doesn't say
otherwise.  ;-)

> 2. How does this apply or not apply to initializations
>    that are NOT required by the language?  For example,
> 
>    type Byte is range 0 .. 255;
>    for Byte'Size use 8;
> 
>    type Buffer is array (Positive range <>) of Byte;
>    pragma Pack (Buffer);
> 
>    B : Buffer (1..Length_Of_Message);
>    for B'Address use Address_Of_Message;
> 
>    -- compiler A fills the space of any declared buffer with
>    -- zeroes.  The language does not require this.  How does
>    -- erasing the received message fit with the Ada 95 rules?

Without pragma Import, the compiler can do what it likes -- initialize B
or not.  I suspect most compilers do not.  I think compilers should not.

With pragma Import on B, I would consider it a bug for a compiler to
initialize B, although I'm not sure I can prove that from the RM.

Then there's pragma Normalize_Scalars, which probably has some effect on
all this.

- Bob




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

* Re: Portability questions
  2000-04-25  0:00 ` Robert A Duff
@ 2000-04-25  0:00   ` Robert Dewar
  2000-04-25  0:00     ` Robert A Duff
  0 siblings, 1 reply; 4+ messages in thread
From: Robert Dewar @ 2000-04-25  0:00 UTC (permalink / raw)


In article <wccbt2ycni0.fsf@world.std.com>,
  Robert A Duff <bobduff@world.std.com> wrote:

> Without pragma Import, the compiler can do what it likes
> initialize B or not.  I suspect most compilers do not.  I
> think compilers should not.

Why do you think that? This is a case where the quality and
efficiency of the code is greatly improved by making sure
that there are no unused garbage bits in the value, which can
otherwise happen with packed arrays. This is very similar to
the trade off choice of whether to clear garbage bits in records
to speed up record comparisons.

> With pragma Import on B, I would consider it a bug for a
> compiler to initialize B, although I'm not sure I can prove
> that from the RM.

Most certainly pragma Import suppresses the initialization, and
I find Bob's "not sure" here odd. This is one of the cases
in which GNAT gives a helpful warning:

Warning: default initialization of x may modify overlaid storage
Warning: packed array components will be initialized to zero
Warning: Use pragma Import for x to suppress initialization
                                                  RM B.1(24)

As you see, this is a case where GNAT includes the RM reference,
and it seems clear enough, no?

24   The declaration of an imported object shall not include an
explicit initialization expression.  Default initializations are
not performed.

> Then there's pragma Normalize_Scalars, which probably has some
> effect on all this.

NS certainly causes more default initialization :-)

Robert Dewar


Sent via Deja.com http://www.deja.com/
Before you buy.




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

* Re: Portability questions
  2000-04-25  0:00   ` Robert Dewar
@ 2000-04-25  0:00     ` Robert A Duff
  0 siblings, 0 replies; 4+ messages in thread
From: Robert A Duff @ 2000-04-25  0:00 UTC (permalink / raw)


Robert Dewar <robert_dewar@my-deja.com> writes:

> In article <wccbt2ycni0.fsf@world.std.com>,
>   Robert A Duff <bobduff@world.std.com> wrote:
> 
> > Without pragma Import, the compiler can do what it likes
> > initialize B or not.  I suspect most compilers do not.  I
> > think compilers should not.
> 
> Why do you think that? This is a case where the quality and
> efficiency of the code is greatly improved by making sure
> that there are no unused garbage bits in the value, which can
> otherwise happen with packed arrays. This is very similar to
> the trade off choice of whether to clear garbage bits in records
> to speed up record comparisons.

Yes, you're right.  If there are gap bits in between components, then it
makes perfect sense for a compiler to set the whole thing to zero.

> > With pragma Import on B, I would consider it a bug for a
> > compiler to initialize B, although I'm not sure I can prove
> > that from the RM.
> 
> Most certainly pragma Import suppresses the initialization, and
> I find Bob's "not sure" here odd.

Well, I was just too lazy to look it up.  ;-)

- Bob




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

end of thread, other threads:[~2000-04-25  0:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-04-24  0:00 Portability questions Wes Groleau
2000-04-25  0:00 ` Robert A Duff
2000-04-25  0:00   ` Robert Dewar
2000-04-25  0:00     ` 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