Re: SV: Re: New Book: The School of Niklaus Wirth

Laurent Guerby <>
19 Nov 2000 20:28:50 -0500

          From comp.compilers

Related articles
Re: Re: New Book: The School of Niklaus Wirth (Orlando Llanes) (2000-11-05)
Re: New Book: The School of Niklaus Wirth (Gabor DEAK JAHN) (2000-11-11)
Re: New Book: The School of Niklaus Wirth (2000-11-16)
SV: Re: New Book: The School of Niklaus Wirth (Mikael Lyngvig) (2000-11-17)
Re: SV: Re: New Book: The School of Niklaus Wirth (Laurent Guerby) (2000-11-19)
| List of all articles for this month |

From: Laurent Guerby <>
Newsgroups: comp.compilers
Date: 19 Nov 2000 20:28:50 -0500
Organization: Club-Internet (France)
References: 00-11-046 00-11-082 00-11-120 00-11-121
Keywords: Ada, types
Posted-Date: 19 Nov 2000 20:28:50 EST

"Mikael Lyngvig" <> writes:
> Actually, Ada83 did not define an unsigned type, which made the
> language a pain to use for systems oriented tasks such as linkers,
> etc.

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
> exception).

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;
> begin
> Index = Index + 1
> end

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
saturated arithmetic).

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 <>

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.