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: double free Date: Fri, 15 Jul 2016 08:39:58 -0700 Organization: None to speak of Lines: 41 Message-ID: References: <8760sc2aiz.fsf@bsb.me.uk> <57856cf1.441531@news.xs4all.nl> <9cfaefc2-92a1-4e03-aa6b-d071a0988c87@googlegroups.com> <4gugob9jk24ovphk6kb8l9365pf8fap1nc@4ax.com> <87eg6vqb4y.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="12919"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19oaDffqoYmSsQnkcaEsM+a" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:bD5CZxCgaG7SOqZt6zBNuc71++o= sha1:ZyG01X510SmxTp3RGH8NXXIsUNc= Xref: csiph.com comp.lang.c:90401 BartC writes: > On 15/07/2016 14:33, Ben Bacarisse wrote: >> BartC writes: >>> The problem was, the access code worked exactly the same for each! >> Something is wrong with your compiler then. These two accesses: >> >>> FooStruct F; >>> int i; >>> >>> F=*Array1[i]; >>> F=*Array2[i]; >> >> are very different. If you've set up Array1 and Array2 so that they are >> both valid, they will generate different code and access different >> locations. > > I'm not talking about the generated code. If A1 actually is a pointer to > array and A2 is an array of pointers, then you would expect the > generated code to access a FooStruct element to be different. > > My issue is that you can access these very different structures using > the identical C expression. [...] One more time. An array expression is, in most but not all contexts, implicitly converted to a pointer to the array's initial element. Because of that, an expression `a[i]` is valid, but has a different meaning, whether `a` is a pointer or an array. You can of course construct more complicated examples of this. I am not trying to say that this language feature was a good idea. In fact, I don't think it was. I am simply describing how it works. You seem to be astonished and appalled every time you encounter this. Most of the rest of us accept it and move on with our lives. -- 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"