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.<br>
Peter<br><br><div><span class="gmail_quote">On 8/26/08, <b class="gmail_sendername">Lux, James P</b> <<a href="mailto:james.p.lux@jpl.nasa.gov">james.p.lux@jpl.nasa.gov</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br> <br> -----Original Message-----<br> From: <a href="mailto:beowulf-bounces@beowulf.org">beowulf-bounces@beowulf.org</a> [mailto:<a href="mailto:beowulf-bounces@beowulf.org">beowulf-bounces@beowulf.org</a>] On Behalf Of Perry E. Metzger<br>
Sent: Tuesday, August 26, 2008 8:06 AM<br> To: Michael H. Frese<br> Cc: <a href="mailto:Beowulf@beowulf.org">Beowulf@beowulf.org</a><br> Subject: Re: [Beowulf] Stroustrup regarding multicore<br> <br> <br> "Michael H. Frese" <Michael.Frese@NumerEx-LLC.com> writes:<br>
> C is not much better. I once worked a young computational programmer<br> > for almost a week to get him to prove to himself that a C source<br> > program couldn't walk through a 2-d array the hard way as fast as a<br>
> Fortran source program unless the stepping was coded by hand.<br> <br> I don't understand what that means. I've been programming in C for<br> about 25 years, and I have known Fortran since the mid-1970s.<br>
<br> > He didn't believe that a 2-d array in C is syntactically a 1-d array<br> > of pointers to 1-d arrays,<br> <br> He was right. You are just plain wrong.<br> <br> char foo[10][10]<br> <br> allocates 100 consecutive addresses in memory.<br>
<br> In case you don't believe me, try out the following program:<br> <br> ----------------------------------------------------------------------<br> #include <stdio.h><br> <br> char foo[10][10];<br> <br> int main(int argc, char **argv)<br>
{<br> int i, j;<br> <br> for (i = 0; i < 10; i++)<br> for (j = 0; j < 10; j++)<br> printf("%d\n",
&(foo[i][j]));<br> }<br> ----------------------------------------------------------------------<br> <br> It will print 100 consecutive integers, the addresses of the character<br> array elements.<br> <br> > and the row pointers must be fetched from memory!<br>
<br> I call bull. That's just totally false. You clearly don't know how C<br> works.<br> <br> <br>-----------------------------<br>
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.<br> <br> All that is guaranteed is that you can retrieve the successive elements of the array by successive values of the index.<br> <br> Jim Lux<br> <br><br> _______________________________________________<br>
Beowulf mailing list, <a href="mailto:Beowulf@beowulf.org">Beowulf@beowulf.org</a><br> To change your subscription (digest mode or unsubscribe) visit <a href="http://www.beowulf.org/mailman/listinfo/beowulf">http://www.beowulf.org/mailman/listinfo/beowulf</a><br>
</blockquote></div><br>