Re: A[x][y][z]
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Thu, 29 Sep 2005 20:37:18 GMT
sterten@xxxxxxx writes:
> it's awful in C with multi-dimension arrays.
I don't disagree.
C doesn't actually have multi-dimensional arrays. It only has
one-dimensional arrays, but the element type can itself be an array
type; an array of arrays of arrays acts very much like a 3-dimensional
array.
> A[x][y][z] is worse than A[x,y,z] ,
It's fine once you get used to it. Note also that A[x,y,z] is also a
valid expression (though not one that you'd ever want to use). The
comma operator evaluates both operands and yields the result of its
right operand, so A[x,y,z] is equivalent to A[z] (assuming x and y
have no side effects).
And because of the relationship between arrays and pointers, the
actual meaning of A[x][y][z] can vary depending on whether A is an
array of arrays of arrays, or a pointer to an array of pointers to
arrays of pointers to arrays (I think I got that right), or any of a
number of other possibilities. The pointer implementation is actually
more common because it's more flexible.
> is someone successfully running the C-compiler from batch-file,
> first converting all of the latter expressions
> into the corresponding former ones and then compiling it ?
I sincerely hope not.
> And while we're at it, this preprocessing utility should
> also change array definitions like e.g.
> int B[N];
> into int B[N+1];
> since B[N] would not be defined else, only B[0],B[1],..,B[N-1]
And while you're at it, you can do things like:
#define IF if(
#define THEN ){
#define ELSE }else{
#define ELSEIF }else if(
#define ENDIF }
and pretend you're writing in a different language altogether. Except
that you're still really programming in C, with all the drawbacks that
implies, with a thin and fragile layer of a different syntax on top of
it.
People have tried this kind of thing, and it's invariably a bad idea.
The result is something that experienced C programmers won't be able
to read because it doesn't look like C, and experienced programmers in
other languages won't be able to read because it doesn't quite look
like anything else.
There is an underlying logic to the way C is designed. You might not
like it (there are things I dislike myself), but you really should try
to understand it before you try to mess with it.
If you want to program in C, you should learn C, with all its little
quirks. If you dislike C so much, you should pick a different
language.
--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
.
- References:
- A[x][y][z]
- From: sterten
- A[x][y][z]
- Prev by Date: Re: File handling in C
- Next by Date: Re: trying to compile with clock_settime(...)
- Previous by thread: Re: A[x][y][z]
- Next by thread: Re: A[x][y][z]
- Index(es):
Relevant Pages
|