comp.lang.ada
 help / color / mirror / Atom feed
From: Georg Bauhaus <rm.dash-bauhaus@futureapps.de>
Subject: Re: Web browser in Ada
Date: Tue, 27 Apr 2010 14:22:00 +0200
Date: 2010-04-27T14:22:01+02:00	[thread overview]
Message-ID: <4bd6d6e8$0$6892$9b4e6d93@newsspool2.arcor-online.net> (raw)
In-Reply-To: <op.vbtj2ue8z25lew@macpro-eth1.krischik.com>

On 27.04.10 13:41, Martin Krischik wrote:
> Am 23.04.2010, 16:37 Uhr, schrieb Georg Bauhaus
> <rm.dash-bauhaus@futureapps.de>:
> 
>> On 23.04.10 15:56, Maciej Sobczak wrote:
> 
>> BTW, why do we still subscribe to the notion "integer overflow"
>> when the one thing that any sequence of what is commonly known
>> as integers cannot possibly do is to overflow?  Maybe the
>> wording is at the heart of the problem.
> 
> Not at all. This is an integer overflow:
> 
> int dayOfMonth =  32;

I don't think that this is an integer overflow
by the common definition of "integer overflow" (which
relies on "int", not implications of the name "dayOfMonth"
---and also not on "integer").  No overflow there,
just a terrible programming mistake.
In Ada, other than predefined "Integer" and such, there are no
named integer types.  Good thing, as this lack suggests
adding at least range constraints, if not new types.
In C, many programmers seem to think there are integers
and that their name is "int".

(On a 5bit architecture one could even be mislead to
believe that the above declaration would create overflow
(disregarding the logical error), since 32 > 2^5 - 1.
But I think that C's minimum requirement for an "int"
is storing values between -(2^15 - 1) and +(2^15 - 1)---
whatever width the underlying hardware's words do
actually have.)

So the above would "flow over" the range constraint of a
suitably defined Month subtype in Ada.  (Forgetting about
February problems for the moment, that can only to be solved
in type systems such as Qi's.)


> Simplified example of course.

Uhm, the heart of the problem is that "int" is taken to mean,
..., well, ... an integer?  Yes, the above is a logical
error, one that could have been prevented mechanically
by using a good base type system, one that does not
include "the integers".  Which is my point: that it is
a misconception to think of "int" as an integer.
If you think of "int" as what it is: "int", and if you are
smart, then little can go wrong.
This is easier to get right once you have a base type system
that naturally suggest not to think in terms of an
infinite set of arbitrary high school numbers, but of
computer entities.  Like Ada's.  I like this characterization
of C's int:

"The int type was typically the most convenient native
data type for integer math." (*)

The "native" part is what seems lost in stereotypical C
knowledge.

(*) http://www.ibm.com/developerworks/power/library/pa-ctypes3/index.html



  reply	other threads:[~2010-04-27 12:22 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-23  8:03 Web browser in Ada Gautier write-only
2010-04-23 13:56 ` Maciej Sobczak
2010-04-23 14:37   ` Georg Bauhaus
2010-04-27 11:41     ` Martin Krischik
2010-04-27 12:22       ` Georg Bauhaus [this message]
2010-04-27 14:00         ` AdaMagica
2010-04-27 15:30           ` Integer overflow is int overflow (Re: Web browser in Ada) Georg Bauhaus
2010-04-27 16:13             ` Dmitry A. Kazakov
2010-04-27 17:09               ` Georg Bauhaus
2010-04-27 17:56                 ` Dmitry A. Kazakov
2010-04-23 21:33   ` Web browser in Ada Gautier write-only
2010-04-24  0:38     ` Peter C. Chapin
2010-04-25  5:38       ` Gautier write-only
2010-04-25 16:24         ` Peter C. Chapin
2010-04-25 10:41       ` Georg Bauhaus
2010-04-25 16:29         ` Peter C. Chapin
2010-04-26 15:37       ` Warren
2010-04-24  9:51 ` leonid
2010-04-25  5:04   ` Gautier write-only
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox