Re: Mysterious warning [SOLVED]
Re: Mysterious warning [SOLVED]
- Subject: Re: Mysterious warning [SOLVED]
- From: "Michael Ash" <email@hidden>
- Date: Wed, 12 Nov 2008 13:50:48 -0500
On Wed, Nov 12, 2008 at 6:30 AM, Graham Cox <email@hidden> wrote:
>
> On 12 Nov 2008, at 10:20 pm, Graham Cox wrote:
>
>> I just added some fairly old C++ lex/bison code to my app, code that has
>> been in use for a long time elsewhere and works fine. My app is compiling
>> with much stricter warnings than many of my other projects though, and this
>> line is throwing a warning:
>>
>>
>> lvalp->val = strtod( --wptr, &wptr );
>>
>> "warning: operation on 'wptr' may be undefined"
>>
>> wptr is declared:
>>
>> static char* wptr = NULL;
>>
>> Can anyone shed any light on what's wrong here? Hopefully the above is
>> enough to go on.
>
>
> Never mind, I found the answer on a comp.lang.c archive.
>
> Seems that the order of argument evaluation can't be relied upon, so using
> the same argument twice in the function call strtod may or may not invoke
> the preincrement when it should. Moving the preincrement outside the
> function call fixes the issue.
This is interesting. I'm pretty sure that this warning is spurious. It
would make sense if the call were written like this:
strtod( --wptr, wptr );
As there is no sequence point between --wptr and wptr, the order of
evaluation isn't defined and the value passed to the function is also
undefined.
However, you're not passing the value, you're passing the *address*,
which is unaffected by your predecrement. It's true that you're
passing the address of the thing that you're predecrementing, but that
shouldn't matter.
My guess is that gcc is just looking for multiple uses of the same
variable in function calls with side effects like this, and is warning
because you use wptr twice even though there isn't actually a problem.
Of course it's still a good idea to shut the warning up even if it's
not actually correct in this case.
Mike
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden