JoJoModding
2022-11-23 22:40:51 UTC
Hi all,
in the paragraph on address and indirection operators (6.5.3.2 in the C23 draft N3047), there is a footnote (footnote 117 in that draft), which says that
Further, we have that
How is one to read this footnote, and the paragraph in general? Why does it try to say that things are "equivalent" that sometimes are not?
Thanks,
Johannes
in the paragraph on address and indirection operators (6.5.3.2 in the C23 draft N3047), there is a footnote (footnote 117 in that draft), which says that
&*E is equivalent to E (even if E is a null pointer)
This seems to imply that sizeof(&*E) == sizeof(E), which is unexpected if E is an array. For example, on most C compilers, we have sizeof("foo") == strlen("foo")+1, while sizeof(&*"foo") == sizeof(char*). So clearly they are not equivalent.Further, we have that
If an invalid value has been assigned to the pointer, the behavior of the unary * operator is undefined.
However the footnote says that &*E is equivalent to E, so if E is an invalid pointer value, *E would be undefined behavior, but &*E is not? (I'm aware that compilers may treat them equivalent, but this is precisely because *E has undefined behavior even if the immediate child of an & operator.) The sentence quoted above is not part of the constraints, so &* does still remove UB even though "the constraints on the operators still apply"?How is one to read this footnote, and the paragraph in general? Why does it try to say that things are "equivalent" that sometimes are not?
Thanks,
Johannes