delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2004/02/04/00:48:49

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
Date: 04 Feb 2004 07:48:51 +0200
Message-Id: <uy8rj5r98.fsf@elta.co.il>
From: Eli Zaretskii <eliz AT elta DOT co DOT il>
To: djgpp AT delorie DOT com
In-reply-to: <20040203231915.21890.00001154@mb-m06.aol.com> (sterten@aol.com)
Subject: Re: array indices [i][j]
References: <20040203231915 DOT 21890 DOT 00001154 AT mb-m06 DOT aol DOT com>
Reply-To: djgpp AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

> Newsgroups: comp.os.msdos.djgpp
> Date: 04 Feb 2004 04:19:15 GMT
> 
> I would like to use A[i,j,k]  instead of A[i][j][k]

You can't really, not with the effect you want it to make.

> (I haven't yet figured out what exactly goes wrong, just changed all
> ][ to ,   and it compiles but gives strange results)

In C, "i, j, k" is a valid expression: it means "take the value of i,
discard it, take the value of j, discard it, take the value of k".  So
A[i, j, k] is the same as simply A[k], probably not what you want.

> What's the difference between the notations ?

The only correct way to reference a 3-dimensional array in C is
A[i][j][k].  If you _must_ use the [i, j, k] notation, the closest
you can get to it is by defining a macro:

  #define MA(i,j,k) A[i][j][k]

(note the use of parentheses instead of square brackets), or a similar
definition of an inline function.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019