comp.lang.ada
 help / color / mirror / Atom feed
From: Keith Thompson <kst-u@mib.org>
Subject: Re: One other possible reason for the C predominance
Date: Tue, 22 Mar 2011 13:19:01 -0700
Date: 2011-03-22T13:19:01-07:00	[thread overview]
Message-ID: <ln62radi2y.fsf@nuthaus.mib.org> (raw)
In-Reply-To: a88203f7-2693-43fe-842b-b8ca4fbfa726@j13g2000yqj.googlegroups.com

Ludovic Brenta <ludovic@ludovic-brenta.org> writes:
[...]
> In fact, C is bad because it assumes a uniform memory architecture and
> a flat address space.  These assumptions were OK for a few decades but
> nowadays, GPUs with dedicated memory are a common case of non-uniform
> memory architectures; the Cell processor and the rise of massively
> parallel supercomputers is another.  Ada has storage pools to
> represent this kind of thing.
[...]

No, C doesn't assume this.

C provides arithmetic on pointers.  If p is a pointer and i is an
integer, then you have:
    p + i -> p
    i + p -> p
    p - i -> p
    p - p -> i
(Note that the result is the number of pointed-to objects, not
the number of bytes.)

C also provides comparison operations on pointers; p0 < p1 means
that p0 points to a lower memory address than p1 does.

But all of these operations have undefined behavior if the two
pointers don't point into the same object (or, as a special case,
just past the end of the object.)  Since the behavior is undefined,
an implementation could even check for out-of-bounds accesses,
though most don't do so.

For C implementations on systems with a flat address space, all
this tends to work as you'd expect (and it makes it very easy to
shoot yourself in the foot by accidentally going outside the bounds
of the object you're working with).  But it's entirely possible to
implement C on a system where distinct objects exist in distinct
address spaces.  This is by deliberate design.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Nokia
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"



  parent reply	other threads:[~2011-03-22 20:19 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-21 22:36 One other possible reason for the C predominance Yannick Duchêne (Hibou57)
2011-03-22 13:09 ` Ludovic Brenta
2011-03-22 14:05   ` Yannick Duchêne (Hibou57)
2011-03-22 15:12     ` Ludovic Brenta
2011-03-22 15:36       ` Yannick Duchêne (Hibou57)
2011-03-22 20:19       ` Keith Thompson [this message]
2011-03-22 21:54         ` Robert A Duff
2011-03-22 14:56 ` Hoàng Đình Long
2011-03-22 15:06 ` Hoàng Đình Long
     [not found] ` <4af234a8-2294-4e0e-a741-ea7dced2ae62@b22g2000prb.googlegroups.com>
2011-03-22 15:34   ` Yannick Duchêne (Hibou57)
replies disabled

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