[M3devel] BITSIZE on constants?

Jay K jay.krell at cornell.edu
Thu Dec 20 21:50:36 CET 2012




I think go has untyped constants.
But I think Modula-3 constants (expressions) always have a type independent of their use.

 - Jay


> Date: Thu, 20 Dec 2012 13:08:08 -0500
> From: hendrik at topoi.pooq.com
> To: m3devel at elegosoft.com
> Subject: Re: [M3devel] BITSIZE on constants?
> 
> 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

 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20121220/76bba396/attachment-0002.html>


More information about the M3devel mailing list