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: usecases of void foo(char **b) {} Date: Thu, 03 Nov 2016 08:45:14 -0700 Organization: None to speak of Lines: 94 Message-ID: References: <2bf83e98-eb96-4ab6-b1ca-4e6a8bd824f5@googlegroups.com> <5b33a608-8f61-4ea0-be08-080018f5772c@googlegroups.com> <87mvhjo3jw.fsf@bsb.me.uk> <3a09f5ec-d4f7-40fa-9855-b5c3f02ce4e9@googlegroups.com> <87ziljks6k.fsf@bsb.me.uk> <2199a2dd-d844-4f8d-bfe0-6a7c2854277b@googlegroups.com> <87twbqlsin.fsf@bsb.me.uk> <87oa1yljof.fsf@bsb.me.uk> <87ins5k15t.fsf@bsb.me.uk> <87bmxxm6zs.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="1f4b9cbd880ce3f40faed57282e3b9ef"; logging-data="4348"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/ptZSDvTOuzjln8UC1vMSF" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:xN8WRzUUu8VgK5qgYyBL1M+0ZFE= sha1:akFjpWkstAljVIM+XzDpMTbWYPA= Xref: csiph.com comp.lang.c:95655 BartC writes: > On 03/11/2016 06:07, Gareth Owen wrote: >> BartC writes: >>> I am not however spreading disinformation just because my view of C is >>> wider than your narrow one. >> >> Have you considered, even for a second, the possibility that you might >> be wrong? > > Go back and show me what I said that was wrong. We've been trying. > And without having to resort to saying that 6.17.348p4 defines such and > such a word differently, therefore my entire argument is invalid. Do you not accept the C standard as an authority on the language? What evidence would you accept? > It seems 'pointers to arrays' simply do not exist in C as far as Ben > Bacarisse is concerned. This kind of nonsense is what makes discussing things with you so frustrating. *Of course* pointers to array exist. > Or if he grudgingly admits they might, then they > are still dismissed as irrelevant. They're not irrelevant. It just happens to be more convenient to manipulate arrays via pointers to their elements. > Yet I use them in C and they work. I implement the concept in other > languages and they work even better. I really doubt whether I'm wrong. > It seems the 'pointer to first element of array' idiom is so ingrained > with the regulars that the possibility of doing it any other way is > inconceivable. Nonsense. The possibility of doing it differently is perfectly conceivable. A lot of us have worked in languages other than C that have more direct support for operations on arrays than C does. (Implementations of those languages are often written in C, BTW.) And you *can* use pointers to arrays in C if you really want to; nobody will stop you. But decades of experience by thousands of C programmers have indicated that using pointers to array elements is more convenient. Here's an example of two functions that print the values of the elements of an array object. func0() is what I would call idiomatic C; it takes a pointer to the array's initial element. func1() is what I presume is how you would prefer to do it; it takes a pointer to the entire array (as a pointer to an incomplete array type). Again, nobody will stop you from writing func1() -- but the func0() style works just as well and is easier to work with *once you understand the idiom*. #include void func0(int *ptr, size_t size) { for (size_t i = 0; i < size; i ++) { printf(" %d", ptr[i]); } putchar('\n'); } void func1(int (*ptr)[], size_t size) { for (size_t i = 0; i < size; i ++) { printf(" %d", (*ptr)[i]); } putchar('\n'); } int main(void) { int array_object[] = { 10, 20, 30 }; size_t len = sizeof array_object / sizeof array_object[0]; func0(array_object, len); func1(&array_object, len); } Do you think func1() is better than func0()? Why? > (I was constantly being told I was simply wrong about C's 'for' > statement, and now it seems that the authors of Rust feel exactly the > same way. Therefore they must be wrong too.) Your statement about C's "for" statement, if I recall correctly, was an opinion, and of course you're entitled to that opinion. The authors of Rust apparently agree, at least in part, with your opinion -- and that's fine too. But the *fact* is that C programmers are able to use its "for" statement successfully. You don't like it. That's fine. I completely agree that you don't like it. -- 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"