Handling argc==0 in the kernel
Handling argc==0 in the kernel
Posted Mar 29, 2022 20:16 UTC (Tue) by nybble41 (subscriber, #55106)In reply to: Handling argc==0 in the kernel by matthias
Parent article: Handling argc==0 in the kernel
From C99 (draft) ยง6.5.3.2:
> If the operand is the result of a unary * operator, neither that operator nor the & operator is evaluated and the result is as if both were omitted, except that the constraints on the operators still apply and the result is not an lvalue. Similarly, if the operand is the result of a [] operator, neither the & operator nor the unary * that is implied by the [] is evaluated and the result is as if the & operator were removed and the [] operator were changed to a + operator.
So "&argv[1]" is effectively rewritten as "argv+1" and there is no undefined behavior either way. You could even have an expression like "&(*p)" or "&p[0]" where p == NULL and the result will be well-defined (NULL). A conforming compiler cannot assume that argc > 0 based on the presence of "&argv[1]".
