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: Sun, 06 Nov 2016 12:53:11 -0800 Organization: None to speak of Lines: 58 Message-ID: References: <8737j7gd87.fsf@bsb.me.uk> <87twbmfzah.fsf@bsb.me.uk> <87fun6f1j4.fsf@bsb.me.uk> <877f8hgb0p.fsf@bsb.me.uk> <87eg2pedkx.fsf@bsb.me.uk> <87wpghcu23.fsf@bsb.me.uk> <877f8gx44n.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="d0d2eb2bf0baae43eeb9ce130bb24749"; logging-data="22948"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Aw1nfFzmI8du3mpgt+oEv" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:YaCNMGci+iAyZ6tclu5mO6cOugI= sha1:T1zvlap0t0BCBch3bhBm6InkiPg= Xref: csiph.com comp.lang.c:95973 Richard Heathfield writes: [...] > Uh, the only rule (and it isn't a particularly arcane rule) is that, > when used in a value context, the name of an array is treated as a > pointer to its first element. That's not /such/ a big deal, surely? [...] Warning: I'm about to pontificate at some length over something that's not greatly significant. I've seen the rule stated that way before. It's not terribly far from being correct, but it does misstate the rule. The rule, as I know you know, is that an expression of array type (not just the name of an array) is "converted" ("adjusted" would have been a better term) to be an expression of pointer type, unless it's in one of three contexts: the operand of sizeof, the operand of unary "&", or a string literal in an initializer used to initialize an array object. That's still not particularly arcane. (I suggest that "adjusted" would be better than "converted" because the adjustment takes place at compile time. It's the array *expression*, not the value of that expression, that's "converted". Expressions exist only at compile time; values exist only at run time. This "conversion" is closely analogous to the adjustment of parameters of array or function type to pointer type, for which the standard does use the word "adjusted". The word "converted" isn't quite *wrong*, but it does tend to imply a run-time action.) I'm not sure what a "value context" is. Most likely it's an expression context that doesn't require an lvalue. If so, an identifier on the left side of an assignment is clearly not in a "value context", but the array-to-pointer conversion would still apply (and the assignment is invalid because there can be no consistent type for the RHS, and more specifically because it violates the constraints on simple assignment). That's a fairly thin argument, since it only affects the *reason* that a particular construct is invalid (unless there are cases I'm missing). But note also that a string literal in an initializer, like this: char s[] = "hello"; *is* in a value context, and the conversion doesn't apply; the *value* of the string literal is used to initialize s. (I know you referred to the "name of an array", which doesn't apply to "hello" in this case.) (No doubt BartC will seize on this as proof that even the experts can't agree.) -- 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"