Re: New C++ warning about comparing this==NULL
Re: New C++ warning about comparing this==NULL
- Subject: Re: New C++ warning about comparing this==NULL
- From: Clark Cox <email@hidden>
- Date: Thu, 03 Dec 2015 00:02:10 -0800
> On Dec 2, 2015, at 23:03, Jens Alfke <email@hidden> wrote:
>
>
>> On Dec 2, 2015, at 10:41 PM, Clark Cox <email@hidden> wrote:
>>
>>> Widget *w = factory.getCurrentWidget();
>>> Paint *p = w->getPaint();
>>> If the currentWidget is NULL, the second line does this.
>>
>> That counts as a pointer dereference (the special case of &*foo is just that, a special case).
>
> It syntactically looks like one, but it isn’t one. “Dereference” means referencing, i.e. accessing, the memory location pointed to. A nonvirtual method call doesn’t do that.
>
The C++ standard disagrees with you.
> 6.5.3.2 Address and indirection operators
> …
(Special case for &* that you mentioned before):
> 3 The unary & operator yields the address of its operand. If the operand has type ‘‘type’’, the result has type ‘‘pointer to type’’. 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, …
> …
Meat of the matter:
> 4 The unary * operator denotes indirection. If the operand points to a function, the result is a function designator; if it points to an object, the result is an lvalue designating the object. If the operand has type ‘‘pointer to type’’, the result has type ‘‘type’’. If an invalid value has been assigned to the pointer, the behavior of the unary * operator is undefined.102)
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden