Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: How is he doing: int a[2] = { 1, 2 }; printf("%d\n", 2[a]); Date: Sun, 01 Jan 2017 13:25:22 -0800 Organization: None to speak of Lines: 57 Message-ID: References: <87y3yxinjl.fsf@bsb.me.uk> <871swpiiu8.fsf@bsb.me.uk> <5868defa.4980093@news.xs4all.nl> <87ful3q9bt.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="8719ec07cc9cf870a68c352ae34a5c70"; logging-data="6389"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19cz8aDIqPEICP99v74hVXv" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:EmPg32oof1kIVNh4QPtfZYkJ2Ec= sha1:kn4E9Yt6ictEMaglVtU5rFXPqpU= Xref: csiph.com comp.lang.c:100816 BartC writes: > On 01/01/2017 12:00, Ben Bacarisse wrote: >> BartC writes: >>> On 01/01/2017 10:54, Richard Bos wrote: >>>> BartC wrote: >>>>> On 30/12/2016 16:41, Keith Thompson wrote: >>>>>> Which exists because there is no unary "-" for pointers, and negating a >>>>>> pointer makes no sense. >>>>> >>>>> Neither does negating an unsigned int. >>>> >>>> There goes someone who has never studied group theory. >>> >>> What does group theory say about 32- and 64-bit pointers? >> >> Nothing as far as I can see. What's your point? There are lots of >> types in C that don't form a group. C's unsigned ints do. > > Where does it say that in the Standard? All I can find is something that > says they can never overflow because the values wrap around. It doesn't. But someone familiar with mathematical group theory can read the C standard's description of unsigned types and conclude that the set of unsigned int values are a group under the operation of addition. There is no particular reason for the Standard to mention that fact. > My original point was that commutative pointer arithmetic is neither > useful nor sensible as it leads to the 2[a] of the subject line. > > You can bamboozle me with higher mathematics but that won't stop people > being confused by i[A] when they come across it. The remark about group theory was in response to your statement that negating an unsigned int makes no sense. An understanding of simple group theory is one way (not the only one) to demonstrate that negating an unsigned int *can* make perfectly good sense. For any value x, negating that value can be defined to yield a value, called -x, such that -x + x is zero. By this definition, -1U == UINT_MAX, because -1U + UINT_MAX == 0. If you're using unsigned int values in a context where negating an unsigned int doesn't make sense, then don't negate them. The commutativity of the indexing operator is an entirely separate issue. I agree with you that it would have made sense for pointer-plus-integer addition *not* to be commutative, but the fact that it is commutative is a mild oddity, not the serious problem you try to make it out to be. As it happens I've discussed it here: http://stackoverflow.com/a/18393343/827263 -- 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"