[Beowulf] Stroustrup regarding multicore

Peter St. John peter.st.john at gmail.com
Tue Aug 26 12:00:50 PDT 2008


um, since array[i][j] is supposed to be the same as array (i * sizeof
(column declared length))[j], then I think yeah, the values should all be at
consecutive locations as Perry described. I just ran a similar experiment in
Visual Studio 2005, just what was on the box as I read this. I don't think
this is stated in ISO, but is logically consequent to stuff in ISO.
Peter

On 8/26/08, Lux, James P <james.p.lux at jpl.nasa.gov> wrote:
>
>
>
> -----Original Message-----
> From: beowulf-bounces at beowulf.org [mailto:beowulf-bounces at beowulf.org] On
> Behalf Of Perry E. Metzger
> Sent: Tuesday, August 26, 2008 8:06 AM
> To: Michael H. Frese
> Cc: Beowulf at beowulf.org
> Subject: Re: [Beowulf] Stroustrup regarding multicore
>
>
> "Michael H. Frese" <Michael.Frese at NumerEx-LLC.com> writes:
> > C is not much better.  I once worked a young computational programmer
> > for almost a week to get him to prove to himself that a C source
> > program couldn't walk through a 2-d array the hard way as fast as a
> > Fortran source program unless the stepping was coded by hand.
>
> I don't understand what that means. I've been programming in C for
> about 25 years, and I have known Fortran since the mid-1970s.
>
> > He didn't believe that a 2-d array in C is syntactically a 1-d array
> > of pointers to 1-d arrays,
>
> He was right. You are just plain wrong.
>
> char foo[10][10]
>
> allocates 100 consecutive addresses in memory.
>
> In case you don't believe me, try out the following program:
>
> ----------------------------------------------------------------------
> #include <stdio.h>
>
> char foo[10][10];
>
> int main(int argc, char **argv)
> {
>         int i, j;
>
>         for (i = 0; i < 10; i++)
>                 for (j = 0; j < 10; j++)
>                         printf("%d\n", &(foo[i][j]));
> }
> ----------------------------------------------------------------------
>
> It will print 100 consecutive integers, the addresses of the character
> array elements.
>
> > and the row pointers must be fetched from memory!
>
> I call bull. That's just totally false. You clearly don't know how C
> works.
>
>
> -----------------------------
> The example you give is going to be compiler dependent.  There's no
> requirement in K&R (I think.. some scum of the earth has apparently borrowed
> my copy, or it's buried under a pile of papers, so I can't check) that the
> rows be stored in contiguous memory.  In fact, relying on ANY particular
> interpretation of pointer values is dangerous. For all you know the compiler
> or runtime goes out and allocates noncontiguous chunks of memory for each
> and every element of the array.  Pointer arithmetic is deprecated.
>
> All that is guaranteed is that you can retrieve the successive elements of
> the array by successive values of the index.
>
> Jim Lux
>
>
> _______________________________________________
> Beowulf mailing list, Beowulf at beowulf.org
> To change your subscription (digest mode or unsubscribe) visit
> http://www.beowulf.org/mailman/listinfo/beowulf
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.beowulf.org/pipermail/beowulf/attachments/20080826/62cf5b9a/attachment.html>


More information about the Beowulf mailing list