comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <stephen.a.leake.1@gsfc.nasa.gov>
Subject: Re: Representation Clauses And Freezing
Date: 2000/07/17
Date: 2000-07-17T21:31:05+00:00	[thread overview]
Message-ID: <uvgy4qwnc.fsf@gsfc.nasa.gov> (raw)
In-Reply-To: 3973192E.E7337814@acm.com

If you follow the compiler's advice, and change the size and alignment
clauses to:

   for Rec_Type'Size use 16 * System.Storage_Unit;
   for Rec_Type'Alignment use 4;

then it is "happy" again (well, except for all the spaces before the
semicolons, but not around elipses :).

I have no explanation for why the record size and alignment changes
when it is a private type. But why do you care?

We've been around on this topic before; the general consensus has been
that it is better to define a non-tagged record type that has a rep
clause, and include that as a component in a tagged type.

-- Stephe

"Marin D. Condic" <mcondic-nospam@acm.com> writes:

> I am trying to find a reasonable workaround to a problem involving
> representation clauses and tagged records. I believe I am running into
> problems with freezing rules. Below are two compiler listings which are
> very similar. When the record type is visible, the compiler is happy.
> When the record type is private, it complains. The question in my mind
> is *WHY* is there some sort of restriction on this? What compiler
> mission cannot be achieved unless the record is visible? Is there some
> sort of workaround that would enable representation clauses on private
> tagged records? (Inheritance from a rep-claused-tagged-record is its own
> problem!)
> 
> GNAT 3.12p  (19990629) Copyright 1992-1999 Free Software Foundation,
> Inc.
> 
> Compiling: rep_clause_01.ads (source file time stamp: 2000-07-17
> 14:20:14)
> 
>      1. with System ;
>      2. 
>      3. package Rep_Clause_01 is
>      4. 
>      5.     type UInteger_16 is mod 2**16 ;
>      6.     for UInteger_16'Size use 16 ;
>      7. 
>      8.     type Rec_Type is tagged record
>      9.         Field_01        : Uinteger_16           := 0 ;
>     10.         Field_02        : Uinteger_16           := 0 ;
>     11.         Field_03        : Uinteger_16           := 0 ;
>     12.     end record ;
>     13.     
>     14. private
>     15. 
>     16.     for Rec_Type use record
>     17.         Field_01        at  4 range 0..15 ;
>     18.         Field_02        at  6 range 0..15 ;
>     19.         Field_03        at  8 range 0..15 ;
>     20.     end record ;
>     21. 
>     22.     for Rec_Type'Size use 10 * System.Storage_Unit ;
>     23.     for Rec_Type'Alignment use 2 ;
>     24. 
>     25. end Rep_Clause_01 ;
> 
>  25 lines: No errors
> 
> 
> GNAT 3.12p  (19990629) Copyright 1992-1999 Free Software Foundation,
> Inc.
> 
> Compiling: rep_clause_02.ads (source file time stamp: 2000-07-17
> 14:20:14)
> 
>      1. 
>      2. with System ;
>      3. 
>      4. package Rep_Clause_02 is
>      5. 
>      6.     type UInteger_16 is mod 2**16 ;
>      7.     for UInteger_16'Size use 16 ;
>      8. 
>      9.     type Rec_Type is tagged private ;
>     10.     
>     11. private
>     12. 
>     13.     type Rec_Type is tagged record
>     14.         Field_01        : Uinteger_16           := 0 ;
>     15.         Field_02        : Uinteger_16           := 0 ;
>     16.         Field_03        : Uinteger_16           := 0 ;
>     17.     end record ;
>     18. 
>     19.     for Rec_Type use record
>     20.         Field_01        at  4 range 0..15 ;
>     21.         Field_02        at  6 range 0..15 ;
>     22.         Field_03        at  8 range 0..15 ;
>     23.     end record ;
>     24. 
>     25.     for Rec_Type'Size use 10 * System.Storage_Unit ;
>                                      |
>         >>> size for "Rec_Type" too small, minimum allowed is 128
> 
>     26.     for Rec_Type'Alignment use 2 ;
>                                        |
>         >>> alignment for "Rec_Type" must be at least 4
> 
>     27. 
>     28. end Rep_Clause_02 ;
> 
> 
> 
> MDC
> -- 
> ======================================================================
> Marin David Condic - Quadrus Corporation - http://www.quadruscorp.com/
> Send Replies To: m c o n d i c @ q u a d r u s c o r p . c o m
> Visit my web site at:  http://www.mcondic.com/
> 
> "Nothing in the world is more dangerous than sincere ignorance and
> conscientious stupidity."
> 
>     -- Martin Luther King, Jr
> ======================================================================

-- 
-- Stephe




  reply	other threads:[~2000-07-17  0:00 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-07-17  0:00 Representation Clauses And Freezing Marin D. Condic
2000-07-17  0:00 ` Stephen Leake [this message]
2000-07-20  0:00   ` Marin D. Condic
2000-07-20  0:00     ` Stephen Leake
2000-07-21  0:00       ` Marin D. Condic
2000-07-21  0:00         ` Simon Wright
2000-07-22  0:00           ` Marin D. Condic
2000-07-22  0:00             ` tmoran
2000-07-22  0:00               ` Marin D. Condic
2000-07-24  0:00               ` Ted Dennison
2000-07-21  0:00         ` Stephen Leake
2000-07-21  0:00           ` Marin D. Condic
2000-07-21  0:00     ` tmoran
2000-07-18  0:00 ` Tucker Taft
2000-07-18  0:00 ` Nicolas Brunot
replies disabled

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