Sujet : Re: technology discussion → does the world need a "new" C ?
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.cDate : 10. Jul 2024, 21:26:15
Autres entêtes
Organisation : None to speak of
Message-ID : <87sewhuh7c.fsf@nosuchdomain.example.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
User-Agent : Gnus/5.13 (Gnus v5.13)
Michael S <
already5chosen@yahoo.com> writes:
[...]
It does not count, because automatic conversion to a pointer is not
something that happens only during parameter passing. For arrays, it
happens in all contexts except sizeof(). For functions, it happens in
all contexts except function call. Or, may be, including function call,
in this case (but not in case of arrays) it depends on point of view.
The rules are stated in section 6.3.2.1 (same subsection number in
N1570/C11 and N3220/C23).
Array expressions "decay" to pointers in all contexts except:
- The operand of "sizeof"
- The operand of unary "&"
- The operand of a typeof operator (introduced in C23)
- A string literal used to initialize an array
A function designator (an expression of function type) decays to a
pointer in all contexts except:
- The operand of "sizeof" (`sizeof func` is a constraint violation)
- The operand of a typeof operator (introduced in C23)
- The operand of unary "&"
The prefix of a function call is required to be of
pointer-to-function type.
C *could* have required the prefix of a function call to be of
function type. It would have had to add another context to the
rules for function designator decay, plus a rule that an expression
of pointer-to-function type is implicitly dereferenced if it's the
prefix of a function call. Unless I'm missing something (which is
always possible), this would have made no effective difference to
the syntax or semantics of the language. But it's consistently
defined the way it is, and if we're going to get into the fine
details I think it's important to understand the rules.
-- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.comvoid Void(void) { Void(); } /* The recursive call of the void */