comp.lang.ada
 help / color / mirror / Atom feed
From: REH <spamjunk@stny.rr.com>
Subject: Re: C++0x and Threads - a poor relation to Ada's tasking model?
Date: Thu, 13 Aug 2009 09:24:33 -0700 (PDT)
Date: 2009-08-13T09:24:33-07:00	[thread overview]
Message-ID: <ea76ae4c-11c2-4986-ab72-78f5ece43a76@p36g2000vbn.googlegroups.com> (raw)
In-Reply-To: hm5885t02rttpp8lppg5gtib804at4tca8@4ax.com

On Aug 13, 9:51 am, John McCabe <j...@nospam.assen.demon.co.uk> wrote:
> On Wed, 12 Aug 2009 14:24:50 -0700 (PDT), REH <spamj...@stny.rr.com>
> wrote:
>
> >On Aug 12, 4:41 pm, Robert A Duff <bobd...@shell01.TheWorld.com>
> >wrote:
> >> The philosophy has nothing to do with "explicitly".
>
> >Sure it does. I have to *explicitly* throw an exception or call
> >something that throws an exception, to raise an exception in C++. In
> >Ada, I don't. It automatic. A simple assignment can raise an
> >exception.
>
> Although this is not an assignment operation, let's take the
> MIL-STD-1750A instruction set (I know it's probably a bit old hat, but
> it's the last one that I really had to study in any detail!) as an
> example. There is an instruction described in section 5.55 which is a
> single precision integer add.
>
> The effect of this instruction is:
>
> "The Derived Operand (DO) is added to the contents of the RA register.
> The result (a 2's complement sum) is stored in register RA. The
> condition status (CS) is set based on the result in register RA and
> carry. A fixed point overflow occurs if both operands are of the same
> sign and the sum is of opposite sign."
>
> What this is saying is that, for a 16 bit integer:
>
>     type Int16 is range -32768..32767;
>     for Int16'size use 16;  -- or something like that
>
> and some fiddling around...
>
>     x : Int16 := 32767;
>     y : Int16 := 1;
>     z : Int16 := 0;
> begin
>     z := x + y;
> end ...;
>
> In Ada this should raise a Constraint_Error (or Numeric_Error or
> something - forgive my vagueness, I haven't used Ada in anger for a
> while) as the bounds of the type have been passed. In this case, all
> we need to do is handle the fixed point overflow interrupt. We don't
> need additional code to carry out this check. I don't know how common
> this feature in a processor is, but it's very simple to implement in
> hardware and my guess is that many numeric faults are as easy trap
> without having to add code in to do the checks.
>
> In C/C++ this would be a wrapping operation so you would have to
> ignore the FP overflow interrupt. That's not such a big deal, but what
> if you actually wanted to catch it on occasion?
>
> My point I guess is that some processors may have support for
> facilities that map nicely on to Ada's exception handling, some
> probably don't, but generalising in the way you have is not an
> accurate representation (like there being no way to provide an
> accurate representation of an object in C/C++ :-)

You are making the assumption that hardware exceptions map to software
exceptions. An Ada run-time may do this (or it may not). C++ does not
( there is no such animal as C/C++). Ada has specific requirements for
what happens when your Int16 overflows. C++ considered a signed
integer overflow undefined behavior. The compiler is allowed to do
anything it wants.

REH



  reply	other threads:[~2009-08-13 16:24 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-11 15:30 C++0x and Threads - a poor relation to Ada's tasking model? John McCabe
2009-08-11 20:51 ` Maciej Sobczak
2009-08-12 12:25   ` John McCabe
2009-08-12 14:51     ` Maciej Sobczak
2009-08-12 15:56     ` REH
2009-08-12 16:59       ` John McCabe
2009-08-12 17:21         ` REH
2009-08-12 20:41           ` Robert A Duff
2009-08-12 21:15             ` REH
2009-08-13  1:28               ` Randy Brukardt
2009-08-13  2:08                 ` REH
2009-08-13  8:38                   ` Pascal Obry
2009-08-13  8:57                     ` Dmitry A. Kazakov
2009-08-13 11:32                       ` Pascal Obry
2009-08-13 12:28                         ` Dmitry A. Kazakov
2009-08-14  1:15                           ` Brian Drummond
2009-08-14 11:24                           ` Language checks (Was: C++0x and Threads - a poor relation to Ada's tasking model?) Jacob Sparre Andersen
2009-08-14 12:01                             ` Dmitry A. Kazakov
2009-08-14 13:33                               ` REH
2009-08-14 13:48                                 ` John McCabe
2009-08-14 14:51                                   ` John McCabe
2009-08-14 14:13                                 ` Dmitry A. Kazakov
2009-08-14 19:58                                   ` Language checks Robert A Duff
2009-08-15  0:10                             ` Language checks (Was: C++0x and Threads - a poor relation to Ada's tasking model?) Randy Brukardt
2009-08-14 13:10               ` C++0x and Threads - a poor relation to Ada's tasking model? Gautier write-only
2009-08-14 13:16                 ` REH
2009-08-12 21:24             ` REH
2009-08-13 13:51               ` John McCabe
2009-08-13 16:24                 ` REH [this message]
2009-08-14 11:09                   ` John McCabe
2009-08-14 13:00                     ` REH
2009-08-14 14:30                       ` John McCabe
2009-08-14 14:49                         ` REH
2009-08-14 14:54                           ` John McCabe
2009-08-14 15:35                             ` REH
2009-08-14 18:43                               ` Robert A Duff
2009-08-14 18:54                                 ` REH
2009-08-14 22:33                                   ` Robert A Duff
2009-08-15  1:15                                     ` REH
2009-08-15 14:24                                       ` Robert A Duff
2009-08-14 15:09                           ` Hyman Rosen
2009-08-14 15:12                             ` REH
2009-08-13 13:55           ` John McCabe
2009-08-13 16:45             ` REH
2009-08-14 11:14               ` John McCabe
2009-08-12 20:53         ` Maciej Sobczak
2009-08-11 23:53 ` jimmaureenrogers
2009-08-12  0:06   ` Jeffrey R. Carter
2009-08-12  7:26   ` Maciej Sobczak
2009-08-12  5:29     ` stefan-lucks
2009-08-12 15:00       ` Maciej Sobczak
2009-08-12  9:27     ` Ludovic Brenta
2009-08-12 15:14       ` Maciej Sobczak
2009-08-13 12:47         ` Peter C. Chapin
2009-08-13 13:57           ` John McCabe
2009-08-14  7:39           ` Maciej Sobczak
2009-08-14 11:13             ` John McCabe
2009-08-14 12:23               ` Dmitry A. Kazakov
2009-08-14 12:50                 ` John McCabe
2009-08-14 13:50                   ` Dmitry A. Kazakov
2009-08-14 13:58                     ` Niklas Holsti
2009-08-14 14:17                       ` Dmitry A. Kazakov
2009-08-14 22:25                       ` Brian Drummond
2009-08-14 12:56             ` John McCabe
replies disabled

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