comp.lang.ada
 help / color / mirror / Atom feed
* 'size works for SunAda but not GNAT
@ 1996-10-08  0:00 David Haslam
  1996-10-09  0:00 ` Stephen Leake
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: David Haslam @ 1996-10-08  0:00 UTC (permalink / raw)



I have a lot of code like this, which compiles fine
with SunAda 1.1:

	subtype V is integer range 0..63;
	type A is array (1..9) of V;
	for A'size use 9 * 8;

GNAT complains "size for A must be at least 288".
GNAT wants V to be 32 bits, even though it can fit in 8.

If GNAT is correct in rejecting this, then it implies that the
code we have is non-portable (and relied on a Verdix implementation
dependent feature).
If so, how do I write portable rep clauses?
There are two ways of fixing the code for GNAT:
1. use a type instead of a subtype
2. add the line: "for A'component_size use 8;"

Which of these is better?

--
David Haslam                                 Work: David.Haslam@gecm.com
GEC-Marconi S3I Ltd                         Home: dch@sirius.demon.co.uk
Simulation and Training Division    




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

* Re: 'size works for SunAda but not GNAT
  1996-10-08  0:00 'size works for SunAda but not GNAT David Haslam
@ 1996-10-09  0:00 ` Stephen Leake
  1996-10-09  0:00 ` Robert Dewar
  1996-10-11  0:00 ` Alan Brain
  2 siblings, 0 replies; 5+ messages in thread
From: Stephen Leake @ 1996-10-09  0:00 UTC (permalink / raw)



David Haslam wrote:
> 
> I have a lot of code like this, which compiles fine
> with SunAda 1.1:
> 
>         subtype V is integer range 0..63;
>         type A is array (1..9) of V;
>         for A'size use 9 * 8;
> 
> GNAT complains "size for A must be at least 288".
> GNAT wants V to be 32 bits, even though it can fit in 8.
> 
> If GNAT is correct in rejecting this, then it implies that the
> code we have is non-portable (and relied on a Verdix implementation
> dependent feature).

Well, non-portable between Ada83 and Ada95, at least. Although, I
suspect there are other Ada83 compilers that reject this also.

> If so, how do I write portable rep clauses?
> There are two ways of fixing the code for GNAT:
> 1. use a type instead of a subtype
> 2. add the line: "for A'component_size use 8;"
> 
These are certainly good choices; 2 is not Ada83, but it is standard
Ada95 (note that not all attributes GNAT supports are standard Ada95).

> Which of these is better?

If you want Ada83 portability, you have to pick 1. If you can use Ada95,
1 is better if ALL uses of type V must be 8 bits; 2 is better if only
THIS use of V needs 8 bits.
> 
> --
> David Haslam                                 Work: David.Haslam@gecm.com
> GEC-Marconi S3I Ltd                         Home: dch@sirius.demon.co.uk
> Simulation and Training Division

-- 
- Stephe




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

* Re: 'size works for SunAda but not GNAT
  1996-10-08  0:00 'size works for SunAda but not GNAT David Haslam
  1996-10-09  0:00 ` Stephen Leake
@ 1996-10-09  0:00 ` Robert Dewar
  1996-10-11  0:00 ` Alan Brain
  2 siblings, 0 replies; 5+ messages in thread
From: Robert Dewar @ 1996-10-09  0:00 UTC (permalink / raw)



David asked

"I have a lot of code like this, which compiles fine
with SunAda 1.1:

        subtype V is integer range 0..63;
        type A is array (1..9) of V;
        for A'size use 9 * 8;

GNAT complains "size for A must be at least 288".
GNAT wants V to be 32 bits, even though it can fit in 8.

If GNAT is correct in rejecting this, then it implies that the
code we have is non-portable (and relied on a Verdix implementation
dependent feature).
If so, how do I write portable rep clauses?
There are two ways of fixing the code for GNAT:
1. use a type instead of a subtype
2. add the line: "for A'component_size use 8;"

Which of these is better?"



This was indeed Verdix dependent code. Verdix allows a size clause to
affect the internal representation of an array, which GNAT does not.
Both Ada 83 AI's and the Ada 95 RM:

53   A Size clause on a composite subtype should not affect the internal
layout of components.


recommend against this.
Of your two solutions, the component size solution is portable. You can
use a type, but you should still use a component clause. When you say

  type V is range 0 .. 63;

GNAT happens to chose Short_Short_Integer as the base type, which has a
default Object_Size of 8 bits, but some other implementation can chose
a different base type and give a different default component size.

Always specify all characteristics that are implementation dependent.

A solution that would also work in both compilers is just to give a Size
clause for the type or subtype. GNAT will use this size as the default
component size, but again, this is not required, and you should really
always specify the component size if it is important to you!






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

* Re: 'size works for SunAda but not GNAT
  1996-10-11  0:00 ` Alan Brain
@ 1996-10-11  0:00   ` Robert Dewar
  0 siblings, 0 replies; 5+ messages in thread
From: Robert Dewar @ 1996-10-11  0:00 UTC (permalink / raw)



Alan said

"I'd also put in some "use at mod..." clauses as well, many compilers
insist on word boundaries for large objects."


There is no need to override default alignments except in very unusual
cases. Also, unless you have to be Ada 83 compatible, the preferable
form of this is

   for x'alignment use ...






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

* Re: 'size works for SunAda but not GNAT
  1996-10-08  0:00 'size works for SunAda but not GNAT David Haslam
  1996-10-09  0:00 ` Stephen Leake
  1996-10-09  0:00 ` Robert Dewar
@ 1996-10-11  0:00 ` Alan Brain
  1996-10-11  0:00   ` Robert Dewar
  2 siblings, 1 reply; 5+ messages in thread
From: Alan Brain @ 1996-10-11  0:00 UTC (permalink / raw)



David Haslam wrote:
> 
> I have a lot of code like this

>         subtype V is integer range 0..63;
>         type A is array (1..9) of V;
>         for A'size use 9 * 8;
> 
> GNAT complains "size for A must be at least 288".

> There are two ways of fixing the code for GNAT:
> 1. use a type instead of a subtype
> 2. add the line: "for A'component_size use 8;"
> 
> Which of these is better?

2, definitely.
When using rep clauses, it is good engineering practice to specify
everything, every component. Why? Because there are so many ways for
different compilers to use different representations in records (for
example). It's easy to miss one bit, the compiler doesn't complain, but
the memory dump shows a memory allocation quite different from the one
intended. I know from personal and painful experience in defining a data
type used for communications between an i860 and a KAV-30.

I'd also put in some "use at mod..." clauses as well, many compilers
insist on word boundaries for large objects.

----------------------      <> <>    How doth the little Crocodile
| Alan & Carmel Brain|      xxxxx       Improve his shining tail?
| Canberra Australia |  xxxxxHxHxxxxxx _MMMMMMMMM_MMMMMMMMM
---------------------- o OO*O^^^^O*OO o oo     oo oo     oo  
                    By pulling Maerklin Wagons, in 1/220 Scale




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

end of thread, other threads:[~1996-10-11  0:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-10-08  0:00 'size works for SunAda but not GNAT David Haslam
1996-10-09  0:00 ` Stephen Leake
1996-10-09  0:00 ` Robert Dewar
1996-10-11  0:00 ` Alan Brain
1996-10-11  0:00   ` Robert Dewar

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