Article View: vmsnet.internals
Article #332Re: C Language question
From: MILLER
Date: Thu, 08 Oct 1992 21:49
Date: Thu, 08 Oct 1992 21:49
23 lines
1098 bytes
1098 bytes
>Question: in C, if one declares char a[I][J], is there anything in the
Remember: a[i] really means *(a+i) using the rules for pointer addition.
a[i] is a macro construct.
So a[i][j] really works out to *((char *)&*(a+i) + j), I think.
So "a" has an "element size" if J characters in this context.
If we declare "char *b = a;" then the following should work:
a[i][b] == *((b+i*J) + j)
and
&a[i][b] == ((b+i*J) + j)
In as much as linear array elements are contiguous, so are multi-
dimentional array elements, since they are simply arrays of arrays.
Check K&R for details (see pointer arithmatic, and multinet-dimentional
arrays). I have no idea what ANSI has to say on the subject.
-bruce
Technical Details
Message-ID:
<718580974.504412.MILLER@TGV.COM>Path:
arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!rutgers!usc!news.service.uci.edu!unogate!mvb.saic.com!macro32Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!rutgers!usc!news.service.uci.edu!unogate!mvb.saic.com!macro32 From: MILLER@TGV.COM Newsgroups: vmsnet.internals Subject: Re: C Language question Message-ID: <718580974.504412.MILLER@TGV.COM> Date: 8 Oct 92 21:49:34 GMT Organization: Macro32<==>Vmsnet.Internals Gateway Lines: 23 X-Gateway-Source-Info: Mailing List