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: Difference between these pointer syntaxes Date: Mon, 15 Aug 2016 13:32:28 -0700 Organization: None to speak of Lines: 73 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> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="3425"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/eTAR+mFv/uqpIiSfsdD1h" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:n+yjWX/rooYRbCyIn53aa2VRnvw= sha1:GJpn8Zh6L3dS3+rxtiME2eebwNA= Xref: csiph.com comp.lang.c:92319 BartC writes: > On 15/08/2016 20:27, Keith Thompson wrote: >> BartC writes: > >>> What can you do with an array object, once created, that you can't do >>> exclusively with pointers? >> >> You can compute its size. You can copy its contents to another object. > > With memcpy? That uses pointers. Yes. You said "exclusively with pointers". You can't validly call memcpy unless there's something to copy. >> You can take its address (the address of an array object is distinct >> from the address of one of its elements; it has a different type). > > But no one ever does. Incorrect. Indexing a 2-dimensional array involves taking the address of a row, which is an array. >>> I suggest that C's treatment is more complicated than it needed to be. >>> Anyone can understand the difference between Array and Pointer in Pascal >>> for instance, because it's genuinely simple. >> >> You don't merely suggest it, you (seemingly deliberately) overstate its >> complexity and understate its consistency. > > Well, I wouldn't be able to explain it in detail to anyone else. I'm not convinced of that, but you certainly haven't tried. > There > are too many holes. There are too many things that magically happen to > array names and array times. There is a huge crossover between arrays > and pointers. There is no language help to stop you abusing a bare > pointer as an array, or an array as pointer. Even something as universal > as a[i] syntax, C can't resist meddling with by allowing i[a]. Instead > of pointers to arrays of T, people almost exclusively use pointers to T, > allowing more opportunities for errors. > > In short, it's a mess. It is entirely consistent, though admittedly odd and sometimes counterintuitive. Your attempts to "explain" it to others hide that fact. What is your goal, to make sure that everyone else is as confused as you are? Please just stop. > The best I could do would be to take a conventional array/pointer type > model WHERE THE TWO ARE DISTINCT, Arrays and pointer types are distinct. > and suggest how it could be emulated > in C to best of the language's ability. No emulation is needed. That's what C does. > With the proviso that C has > limited means to warn of any errors if the user gets some things mixed up. A lot of people are confused by the relationship between arrays and pointers in C. Every time you claim that arrays and pointers are the same thing, **you make it worse**. -- 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"