comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Null Range in Unconstrasined Array
Date: Wed, 09 Sep 2009 09:00:39 -0400
Date: 2009-09-09T09:00:39-04:00	[thread overview]
Message-ID: <wcchbvc2ryg.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: uk5088qig.fsf@stephe-leake.org

Stephen Leake <stephen_leake@stephe-leake.org> writes:

> Adam Beneschan <adam@irvine.com> writes:
>
>> To elaborate on this a bit further: Suppose you define a record type
>> for reading a file with Ada.Direct_IO, that looks something like this:
>>
>>   type Employee_Data is record
>>       Name     : String (1 .. 50);
>>       Address1 : String (1 .. 40);
>>       Address2 : String (1 .. 40);
>>       City     : String (1 .. 30);
>>       State    : String (1 .. 2);
>>       ...
>>   end record;
>>
>> (Reminds me of my COBOL programming days...)  Anyway, it would be very
>> unexpected for the compiler to put two extra integers in the record
>> for each of these strings, and it would mess up your file I/O.  
>
> If you expect the layout of this record to match your file, you must
> provide a representation clause.

Good idea.

> It _could_ depend on whether there's a pragma Pack, or a
> representation clause, for the record. In the absence of such, I would
> expect the compiler to treat these components the same way it treats
> separate objects.

Yes.

>...Which means I would expect the bounds to be stored
> with the object.

Most compilers, including GNAT, will not store the bounds with the
object (whether it's a component or a standalone object).
Think about an array of a million of those records:
you don't want 1,000,000 copies of the number 50 stored
at run time.  That number is known to the compiler, and can
be plugged in wherever needed (e.g. when you say
"for X in A(Y).Name'Range loop", the compiler knows that's
just "for X in 1..50 loop".

> But that's just my expectations; compilers are free to do whatever they
> want, as long as it meets the standard.

Right.

- Bob



  reply	other threads:[~2009-09-09 13:00 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-01  1:28 Null Range in Unconstrasined Array Rick
2009-09-01  3:11 ` Randy Brukardt
2009-09-01 14:50 ` Adam Beneschan
2009-09-01 15:34   ` Robert A Duff
2009-09-06 12:11     ` Peter C. Chapin
2009-09-06 12:41       ` Robert A Duff
2009-09-08 17:54         ` Adam Beneschan
2009-09-09  8:35           ` Stephen Leake
2009-09-09 13:00             ` Robert A Duff [this message]
2009-09-09 19:22             ` sjw
2009-09-10 23:24               ` Stephen Leake
replies disabled

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