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: Mon, 31 Oct 2016 08:10:13 -0700 Organization: None to speak of Lines: 42 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="c5bda195eda2f24b3ba8be744a1d8f44"; logging-data="15344"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18kd00ba5v2J24sP7ELWYKq" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:XbYayFxfvj6kYhAdEvV1F2/1nks= sha1:GY+RHjklZHuvxV5ykNlWO9ktIx4= Xref: csiph.com comp.lang.c:95441 BartC writes: > On 31/10/2016 14:20, Richard Heathfield wrote: >> On 31/10/16 13:16, Pascal J. Bourguignon wrote: [...] >>> In C, basically a pointer is equivalent to array. >> >> Except when it isn't. For example: > > Here we go again... Yes, here we go again. > Take the char** parameter type in the subject; each "*" might denote a > pointer to a single object, or a pointer to multiple objects, the common > idiom to pass an array (or possibly a string when char*) to a function. A (valid non-null) pointer is always a pointer to a single object. That single object may or may not be the initial element of an array object. > Hence char** can be interpreted in four different ways, some of which > could involve arrays. Yes, some uses of char** may *involve* arrays. That doesn't mean pointers and arrays are equivalent. [...] > But if arrays /are/ involved, then they can be handled by this single > pointer to pointer parameter. It's magic. No, it's not magic. It's a consequence of a reasonably straightforward set of rules laid out in the standard. Stop trying to make this more confusing than it really is. [...] -- 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"