Computers and heat density
der Mouse
mouse at Rodents.Montreal.QC.CA
Sun Aug 13 23:43:27 CDT 2006
> No, they aren't. But I personally never remembered if C stores
> arrays row major, or column major.
I can't either, but that's because I can't recall which way is row
major and which way is column major. But when I recall that
int foo[20];
declares foo to be int[20], and
int bar[10][20];
declares bar[x] to be int[20] ("int (bar[10])[20];") then it all makes
sense.
> But really, it gets to me when I see code like:
> for (i = 0 ; i < MAX ; i++)
> foo[i] = 0;
> when it could easily be replaced with:
> memset(foo,0,sizeof(foo));
While I realize you said "when", I would point out that this is a valid
replacement only when foo is an integral type. If foo is float or
pointer, this is not a safe thing to do (except in code that's
sufficiently hardware-specific that you can assume the in-memory layout
of the relevant data type - and know that all-0-bits is TRT).
Also, note that this assumes that sizeof(foo) is MAX*sizeof(foo[0]),
though I realize this is easy to fix in the memset call.
/~\ The ASCII der Mouse
\ / Ribbon Campaign
X Against HTML mouse at rodents.montreal.qc.ca
/ \ Email! 7D C8 61 52 5D E7 2D 39 4E F1 31 3E E8 B3 27 4B
More information about the cctalk
mailing list