|Re: Re: New Book: The School of Niklaus Wirth email@example.com (Orlando Llanes) (2000-11-05)|
|Re: New Book: The School of Niklaus Wirth firstname.lastname@example.org (Gabor DEAK JAHN) (2000-11-11)|
|Re: New Book: The School of Niklaus Wirth email@example.com (2000-11-16)|
|SV: Re: New Book: The School of Niklaus Wirth firstname.lastname@example.org (Mikael Lyngvig) (2000-11-17)|
|Re: SV: Re: New Book: The School of Niklaus Wirth email@example.com (Laurent Guerby) (2000-11-19)|
|From:||Laurent Guerby <firstname.lastname@example.org>|
|Date:||19 Nov 2000 20:28:50 -0500|
|References:||00-11-046 00-11-082 00-11-120 00-11-121|
|Posted-Date:||19 Nov 2000 20:28:50 EST|
"Mikael Lyngvig" <email@example.com> writes:
> Actually, Ada83 did not define an unsigned type, which made the
> language a pain to use for systems oriented tasks such as linkers,
Most Ada 83 compiler provided some form of unsigned integer types,
the real pain was doing portable things.
> An unsigned type was added to Ada9x, however. Ada9x also added
> another "basic integer" type - the modulo type, which is a kind of
> "unsigned wrap-around type", which is an integer that silently wraps
> around when it reaches the modulo value (without throwing an
From the Ada 95 Reference Manual: <<A modular type has a base range
whose lower bound is zero, and has operations with ``wraparound''
semantics. Modular types subsume what are called ``unsigned types''
in some other languages.>>
> You'd write the code shown below in Ada95 (or something like it; I
> haven't looked at Ada for a few years):
> Index is mod TableSize;
> Index = Index + 1
Unless TableSize is a "compile time" constant this declaration is
illegal (the compiler would have a hard time choosing the appropriate
machine type and generating code). And affectation is ":=" as in
Pascal, but ";" is a statement terminator not separator ;-).
Some people said that the allowance of non-power of two modulus was a
unfortunate procedural mistake in the standardization effort
(compeletly overlooked until too late), and it is not recommanded
anyway to use modular types for this kind of code, the C version is
perfectly appropriate in Ada.
Modular types are designed to do traditional "unsigned" things,
logical operators are available ("and", "or", "xor", "not"), plus
shift, arithmetic shifts and rotate functions on a few modular types
(Interfaces.Unsigned_16, Unsigned_32 and the like).
Like for regular Integer types, compiler must support at least up to
16 bits modular types.
The standard also mentions the possibility of an implementation
providing "nonstandard integer types" (if one machine has support for
Personally I use Ada modular types for random number generators,
hashing or having cosmetic counters that silently wrap around instead
of generating an overflow exception ;-).
BTW, out of curiosity, what other language provide a rotate operator?
Laurent Guerby <firstname.lastname@example.org>
Return to the
Search the comp.compilers archives again.