comp.lang.ada
 help / color / mirror / Atom feed
* Confused about Attribute Size?
@ 2002-01-22  7:39 Zebylon
  2002-01-22 19:08 ` Patrick Hohmeyer
  2002-01-22 22:56 ` Mark Johnson
  0 siblings, 2 replies; 8+ messages in thread
From: Zebylon @ 2002-01-22  7:39 UTC (permalink / raw)


Hi,

I'm a newbie in Ada but I saw an Ada example that confused me a bit, here it
is:

type My_Type is
    (startbit,
     endbit,
     timeout,
     spare,
     nextbit,
     ......
     ......
     lastbit);

for My_Type use
    (startbit =>0,
     endbit=>1,
     timeout=>2,
     spare=>3,
     nextbit=>4,
     ......
     ......
     lastbit=>15);

for My_Type'Size use 8;

type My_Type_Array is array (My_Type) of Boolean;

What I don't understand is how you can assign the size to 8 bits? How will
this work when
there are 16 bits in the type? What will be the size of the array?
This example was in Ada 83 could this be a clue?

Thanks

/S






^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: Confused about Attribute Size?
@ 2002-01-22  8:00 Christoph Grein
  0 siblings, 0 replies; 8+ messages in thread
From: Christoph Grein @ 2002-01-22  8:00 UTC (permalink / raw)


> 
> type My_Type is
>     (startbit,
>      endbit,
>      timeout,
>      spare,
>      nextbit,
>      ......
>      ......
>      lastbit);

This assigns _values_ (not bit positions) to the enumeration literals that shall 
be used to represent them internally, i.e. startbit has the value (or is another 
name for) 0, lastbit the value 15. However you have no access to the internal 
values (you can't add them e.g. startbit + timeout is illegal).

> for My_Type use
>     (startbit =>0,
>      endbit=>1,
>      timeout=>2,
>      spare=>3,
>      nextbit=>4,
>      ......
>      ......
>      lastbit=>15);
> 
> for My_Type'Size use 8;

Since a value of 15 = 2#00001111# can be represented in 8 bits, there is no 
problem.

> type My_Type_Array is array (My_Type) of Boolean;
> 
> What I don't understand is how you can assign the size to 8 bits? How will
> this work when
> there are 16 bits in the type? What will be the size of the array?
> This example was in Ada 83 could this be a clue?

In Ada95, there is no need to explicitly define this default representation, see 
RM 13.4(8).



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

end of thread, other threads:[~2002-01-24  4:11 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-01-22  7:39 Confused about Attribute Size? Zebylon
2002-01-22 19:08 ` Patrick Hohmeyer
2002-01-22 22:56 ` Mark Johnson
2002-01-23  2:20   ` Jeffrey Carter
2002-01-23 14:56     ` Mark Johnson
2002-01-23 17:06       ` Jeffrey Carter
2002-01-24  4:11         ` Robert Dewar
  -- strict thread matches above, loose matches on Subject: below --
2002-01-22  8:00 Christoph Grein

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