Hi,
Am Donnerstag, den 15.01.2009, 18:12 +0100 schrieb Dominique Colnet:
> On Tue, 2009-01-13 at 18:40 +0100, Dominique Colnet wrote:
> > > In other words: How do I assign 0xff into a NATURAL_8?
> You cannot (see below).
;-)
> > natural_8 := (0xFF).to_natural_8
> > -- not tested, but should be equivalent to:
> > natural_8 := 255.to_natural_8
> Ooops, sorry. Forget my previous comment. Il will try to be correct and
> clear now:
> 0xFF
> has only one type, and is of type INTEGER_8 and thus is actually value
> -1 mapped on 8 bits.
> Where 255 is of type INTEGER_16 which can be be legally stored into
> a NATURAL_8.
I understand that, but I doubt its usefulness. I think assigning 0xFF to
an INTEGER_8 should be prohibited. If one thinks in bits or hex number
he always should use NATURALs. If he means an integer 255 should be the
choice. If an INTEGER_8 is meant I'd prefer to write {INTEGER_8 -1}
I'm convinced, that whenever hex number formats come to ones mind one
thinks in NATURALS.
> > > 0xff.to_natural_8 gives a precondition violation at runtime, but the
> > > tutorial tells us to use NATURALs this way...
> Well, any negative value will broke the require.
Yes, of course. But 0xff is not negative (in my eyes.)
> Hope this is clear now. BTW, the principle that one expression
> has only one static type regardless the context was a good
> choice I think.
Yes, I also think that. But still think, that writing integers in
hexadecimal format is very stange (and yes, I work in OS business for
embedded systems, so I am familiar to thinking in bit masks, and hex
numbers - integers I know from school and nobody wrote 0xff there when
he meant -1)
If you think 0xff should have type INTEGER_8, then I think a
force_to_natural_8 shall be provided in INTEGER_8, because writing
n: NATURAL_8
n := 0x88.force_to_natural_8
is far better to understand when you mean the most significant bit in
each nibble to be set then writing:
n := 136.to_natural_8
(Even though I'd prefer:
n := 0x88
as you know)
Cheers,
Rapha