<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>I am NOT asking for untyped constants.<br>Constants are typed, and BITSIZE ought to work on them. That is what I am asking for:<br><br><br> CONST a = 1; <br> CONST b = BITSIZE(a); <br><br><br> - Jay<br><br><br><div><div id="SkyDrivePlaceholder"></div>> Date: Thu, 20 Dec 2012 16:34:07 -0600<br>> From: rodney_bates@lcwb.coop<br>> To: m3devel@elegosoft.com<br>> Subject: Re: [M3devel] BITSIZE on constants?<br>> <br>> <br>> <br>> On 12/20/2012 02:50 PM, Jay K wrote:<br>> > I think go has untyped constants.<br>> <br>> Ada has them too, but the rules for when they get implicitly converted to a runtime<br>> type are, well, IMO, bizarre.<br>> <br>> Even if they were more straightforward, there is inevitably a lot of complexity here<br>> that few working programmers will learn or think about, instead hoping everything<br>> will "just work". This can only be according their individual idea of how it<br>> should work, which is nowhere close to being either obvious or universal. Thus<br>> do very subtle bugs occasionally occur, and cause grief all out of proportion to<br>> their frequency.<br>> <br>> > But I think Modula-3 constants (expressions) always have a type independent of their use.<br>> <br>> Yes. All in 2.4.2:<br>> <br>> You can give a constant a type explicitly:<br>> <br>> CONST C : [ - 3 .. 0 ] = - 2;<br>> <br>> in which case, the value must be a member of the type.<br>> <br>> Or you can omit it, in which case, the type of the constant is the type<br>> of the _expression_.<br>> <br>> CONST D = - 2;<br>> <br>> There are many values that belong to more than one type (e.g., - 2<br>> belongs to any subrange of INTEGER that contains it). But every<br>> expression has exactly one type. In this case, the type of every<br>> integer literal is INTEGER. And unary "-" applied to an INTEGER<br>> also has type INTEGER, which is the type of D.<br>> <br>> BTW, this is why we need different spellings for INTEGER and<br>> LONGINT literals, e.g. 10 and 10L. It avoids a morass of implied<br>> type conversion rules, etc., that the language already avoided<br>> before LONGINT. In fact, the same idea is in the original<br>> language for the floating point literals, with "E". "D", or<br>> "X" in the literal spelling, to uniquely denote its type.<br>> <br>> ><br>> > - Jay<br>> ><br>> ><br>> > > Date: Thu, 20 Dec 2012 13:08:08 -0500<br>> > > From: hendrik@topoi.pooq.com<br>> > > To: m3devel@elegosoft.com<br>> > > Subject: Re: [M3devel] BITSIZE on constants?<br>> > ><br>> > > On Thu, Dec 20, 2012 at 11:16:32AM -0600, Rodney M. Bates wrote:<br>> > > ><br>> > > ><br>> > > > On 12/19/2012 11:08 PM, Jay wrote:<br>> > > > >Eh? isn't bitsize(type) valid? It is in C and seems confroversy-free.<br>> > > ><br>> > > > BITSIZE(type) (and BYTESIZE and ADRSIZE) is indeed valid on a _type_ in<br>> > > > Modula-3. At the last paragraph of 2.6.13, it is defined as the size of a<br>> > > > _variable_ of that type. The whole idea is that a compiler should not be<br>> > > > obligated to store a constant in memory.<br>> > > ><br>> > > > Presumably, you know statically what the type of a CONST is, so can't you<br>> > > > just use BITSIZE(TypeOfConst)? If you later changed the constant<br>> > > > to a different type, it wouldn't self-adapt, but likely other places wouldn't<br>> > > > either, or maybe would, but not correctly for your program.<br>> > ><br>> > > Consider BITSIZE(-3). Doesn't it make a difference whether this -3 is<br>> > > to be considered as of type -3..0 or INTEGER, or even -3..-3? THis<br>> > > isn't inherent in the constant, and might on some implementations give<br>> > > BITSIZEs of 2, 64, or even 0, respectively, if meaningful.<br>> > ><br>> > > And if you were to change the language syntax so you'd always have to<br>> > > write something like (-3..0)(-3) to be explicit you'd end up writing<br>> > > everything you's write with BITSIZE(TypeOfConst) and more. What you<br>> > > might gain is a static check that the constant isn't out of bounds.<br>> > ><br>> > > -- hendrik<br>> <br></div> </div></body>
</html>