Re: C Standard Regarding Null Pointer Dereferencing
- From: Tim Rentsch <txr@xxxxxxxxxxxxxxxxxx>
- Date: Fri, 23 Jul 2010 10:30:28 -0700
Shao Miller <sha0.miller@xxxxxxxxx> writes:
On Jul 23, 12:43 pm, Tim Rentsch <t...@xxxxxxxxxxxxxxxxxx> wrote:
If and only if you do not take the text for the unary '*' operator
The expression '*(char *)0' is undefined behavior if it
is evaluated. Any subsequent cast is irrelevant to the
question about whether the behavior is defined.
literally. That text describes undefined behaviour when a null
pointer value has been assigned to the pointer. Here we have a null
pointer, not a nuller pointer value assigned to a pointer.
We agreed that it's possible that that text might be imprecise, and
might need to be addressed, did we not? But it's also possible that
it's precise, and there is no undefined behaviour until casting to
'(void)'.
Would you agree?
I don't. The wording could be better, but there is no
doubt about the meaning. The Standard is written in
formal English but it is not a math textbook, and it's
at best a waste of time to read it like one.
If you want to get technical, it can NEVER be the case
that the operand of an indirection operator has been
assigned. In the expression '*p', where p has been
declared to be of some pointer type, the operand 'p'
has already been converted to a value by virtue of
6.3.2.1p2. There is no difference between '*p' and
'*(char*)0' in this regard -- both operate on values,
not objects. So it's completely nonsensical to try to
understand "has been assigned" as applying to one class
of operand expression but not another. They are all
just values.
.
- Follow-Ups:
- Re: C Standard Regarding Null Pointer Dereferencing
- From: Shao Miller
- Re: C Standard Regarding Null Pointer Dereferencing
- References:
- C Standard Regarding Null Pointer Dereferencing
- From: Shao Miller
- Re: C Standard Regarding Null Pointer Dereferencing
- From: Shao Miller
- Re: C Standard Regarding Null Pointer Dereferencing
- From: Tim Rentsch
- Re: C Standard Regarding Null Pointer Dereferencing
- From: Shao Miller
- C Standard Regarding Null Pointer Dereferencing
- Prev by Date: Re: While Loop Evaluation Help
- Next by Date: Re: Can de-reference operator * be overloaded?
- Previous by thread: Re: C Standard Regarding Null Pointer Dereferencing
- Next by thread: Re: C Standard Regarding Null Pointer Dereferencing
- Index(es):
Relevant Pages
|