[M3devel] BITSIZE on constants?

Hendrik Boom hendrik at topoi.pooq.com
Thu Dec 20 19:08:08 CET 2012


On Thu, Dec 20, 2012 at 11:16:32AM -0600, Rodney M. Bates wrote:
> 
> 
> On 12/19/2012 11:08 PM, Jay wrote:
> >Eh? isn't bitsize(type) valid? It is in C and seems confroversy-free.
> 
> BITSIZE(type) (and BYTESIZE and ADRSIZE) is indeed valid on a _type_ in
> Modula-3.  At the last paragraph of 2.6.13, it is defined as the size of a
> _variable_ of that type.  The whole idea is that a compiler should not be
> obligated to store a constant in memory.
> 
> Presumably, you know statically what the type of a CONST is, so can't you
> just use BITSIZE(TypeOfConst)?  If you later changed the constant
> to a different type, it wouldn't self-adapt, but likely other places wouldn't
> either, or maybe would, but not correctly for your program.

Consider BITSIZE(-3).  Doesn't it make a difference whether this -3 is 
to be considered as of type -3..0 or INTEGER, or even -3..-3?  THis 
isn't inherent in the constant, and might on some implementations give 
BITSIZEs of 2, 64, or even 0, respectively, if meaningful. 

And if you were to change the language syntax so you'd always have to 
write something like (-3..0)(-3) to be explicit you'd end up writing 
everything you's write with BITSIZE(TypeOfConst) and more.  What you 
might gain is a static check that the constant isn't out of bounds.

-- hendrik



More information about the M3devel mailing list