Path: csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Difference between these pointer syntaxes Date: Wed, 17 Aug 2016 09:47:31 -0700 Organization: None to speak of Lines: 45 Message-ID: References: <87mvkkflc0.fsf@bsb.me.uk> <871t1wf8f8.fsf@bsb.me.uk> <87vaz7eg7c.fsf@bsb.me.uk> <87tweqdeuo.fsf@bsb.me.uk> <87y441a697.fsf@bsb.me.uk> <87r39s8w6c.fsf@bsb.me.uk> <4991b886-1f54-4098-bf57-ba59710b99d1@googlegroups.com> <5c08a362-e80f-4dd0-a7eb-c31d3c0be6d9@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="7723"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+FQvZiZNY+dyej7lJTv9ug" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:SfwFutTZnqc+UqEcusQLFWqSfMo= sha1:tHaQpLKM6P/NebdMt+/pZYEg/1A= Xref: csiph.com comp.lang.c:92375 Malcolm McLean writes: > On Wednesday, August 17, 2016 at 1:45:54 AM UTC+1, james...@verizon.net wrote: >> > Look at my post of this morning in this thread (16-Aug 11:01, about >> > 12 1/2 hours your post above). I listed many ways of accessing >> > those simple data structures in nonsense ways, yet the compiler did >> > not object. Apparently almost anything goes. This seems to be a >> > consequence of that innocuous-sounding rule. >> >> Why do you characterize them as nonsense? > > code like i[array[j]] = x > > is clearly garbage code, nonsense, an IOCC entry, an undesirable > construct, geek-talk, something that would fail a code review, > a quirk in the C standard syntax, however you wish to describe it. I agree that it's garbage code, potentially an IOCCC entry (though more obfuscation than that would be needed to win), an undesirable construct, geek-talk I suppose, and almost certainly something that would fail a code review. It is not "nonsense" because, given the declarations of i, array, j, and x, its meaning is unambiguous. I wouldn't call it a quirk in the C standard syntax. It's not a *syntax* problem at all. i, array, j, and x are simply identifiers. Given appropriate declarations, something like some_array[indices[i]] = x; might be perfectly appropriate, where indices is an array containing integer values to be used as indices into some_array. Your objection, I think, is to the fact that both a[i] and i[a] are meaningful and have the same meaning. That's a matter of the *semantics*, not the syntax, of the indexing operator, and it exists simply because there *isn't* a special-case rule that forbids swapping the two operands of the [] operator. (I personally would have preferred to have such a rule, but the benefits would be minor.) -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"