comp.lang.ada
 help / color / mirror / Atom feed
From: Jeff Carter <jrcarter010@earthlink.net>
Subject: Re: 'Size (novice question)
Date: 2000/02/18
Date: 2000-02-18T00:00:00+00:00	[thread overview]
Message-ID: <38ACC0CD.B03EB020@earthlink.net> (raw)
In-Reply-To: 38ACA68D.CEA7E03F@interact.net.au

G wrote:
> Type Byte is mod 2**8;
> for Byte'Size use 8;
> 
> why is the 'Size postfix used to set the size to
> 8 bits when I would have thought that mod 2**8
> did the same thing.

In most cases you would probably be right. BUT ...

It is perfectly OK for the compiler to use more bits than necessary.
Perhaps the architecture is such that loading a 32-bit word into a
register is faster than loading an 8-bit byte. The type definition only
defines the number of values that objects of the type can have (256, in
this case. A 'Size definition instructs the compiler to use a specific
number of bits.

Note that this works both ways:

type Half_Word is mod 2 ** 8;
for Half_Word'Size use 16;

Here we want to use one byte out of a (16-bit) word. The range of values
can be stored in 8 bits, but we are requiring that objects of this type
occupy 16 bits.

-- 
Jeff Carter
"You tiny-brained wipers of other people's bottoms!"
Monty Python & the Holy Grail




       reply	other threads:[~2000-02-18  0:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <38ACA68D.CEA7E03F@interact.net.au>
2000-02-18  0:00 ` Jeff Carter [this message]
     [not found] ` <wccsnyqof2a.fsf@world.std.com>
     [not found]   ` <slrn8aqgfn.15u.lutz@taranis.iks-jena.de>
     [not found]     ` <87aekxlz33.fsf@deneb.cygnus.argh.org>
2000-02-22  0:00       ` 'Size (novice question) Lutz Donnerhacke
2000-02-22  0:00         ` Florian Weimer
2000-02-23  0:00           ` Lutz Donnerhacke
2000-02-22  0:00     ` Vladimir Olensky
2000-02-22  0:00       ` Robert Dewar
replies disabled

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