🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: vmsnet.internals
Article #324

Re: C Language question

#324
From: Robin Fairbairns
Date: Thu, 08 Oct 1992 13:44
41 lines
2579 bytes
In article <23000B53_00073190.00961C83B1DAD300$668_1@UK.AC.KCL.PH.IPG>,
SYSMGR@IPG.PH.KCL.AC.UK writes:
|> (To those who get offended by questions that stray outside a group's main
|> intention - Sorry, please hit delete now. I'm not sure what the appropriate
|> mail list is, and I do know that the folks that follow this one are likely
|> to know!)

Sure as hell is the wrong group - you need comp.lang.c or somesuch.
However, it may not be available as a mailing list: get yourself
Usenet news, Nigel!

|> Question: in C, if one declares char a[I][J], is there anything in the
|> language standard that guarantees that &a[0][0] is the first of a set of
|> I*J contiguous chars, and that a[i+1][0] is guaranteed to be the same
|> storage location as a[i][J] ).

The standard (actually I only have a copy of the 1st DIS, but it's
hardly likely to have changed) says "... The definition of the
subscript operator [] is that E1[E2] is identical to (*(E1+(E2))).
..."  It then goes on to say "... If E is an n-dimensional array
(n>=2) with dimensions ixjx...xk, then E (used as other than an
lvalue) is converted to a apointer to an (n-1)-dimensional array with
dimensions jx...xk.  If the unary * operator is applied to this
pointer explicitly, or implicitly as a result of subscripting, the
result is the pointed-to (n-1)-dimensional array, which is itself
converted to a pointer if used as other than an lvalue.  It follows
from this that arrays are stored in row-major order (last subscript
varies fastest)."

I think that answers your question

|> A friend asserts that it is, and says his experience on several systems
|> 'proves' this. My belief is that there is nothing that says this will
|> always be the case, and that the only constraint is that every valid pointer
|> a[i] will point to J chars. Which of us is right?

Your friend is obviously neither a scientist nor a mathematician ;-)
--
Robin (come back John Drummond) Fairbairns       rf@cl.cam.ac.uk
U of Cambridge Computer Lab, Pembroke St, Cambridge  CB2 3QG, UK
Technical Details
Message-ID: <1992Oct8.134446.3531@infodev.cam.ac.uk>
Path: arc1-ca.pugleaf.net!sparky!uunet!pipex!pavo.csi.cam.ac.uk!cam-cl!rf
References: <23000B53_00073190.00961C83B1DAD300$668_1@UK.AC.KCL.PH.IPG>

Show Full Headers
Complete Article Headers
Newsgroups: vmsnet.internals
Path: arc1-ca.pugleaf.net!sparky!uunet!pipex!pavo.csi.cam.ac.uk!cam-cl!rf
From: rf@cl.cam.ac.uk (Robin Fairbairns)
Subject: Re: C Language question
Message-ID: <1992Oct8.134446.3531@infodev.cam.ac.uk>
Sender: news@infodev.cam.ac.uk (USENET news)
Nntp-Posting-Host: ely.cl.cam.ac.uk
Reply-To: rf@cl.cam.ac.uk (Robin Fairbairns)
Organization: U of Cambridge, England
References: <23000B53_00073190.00961C83B1DAD300$668_1@UK.AC.KCL.PH.IPG>
Date: Thu, 8 Oct 1992 13:44:46 GMT
Lines: 41