Re: New warning in Xcode 7
Re: New warning in Xcode 7
- Subject: Re: New warning in Xcode 7
- From: Rick Mann <email@hidden>
- Date: Tue, 13 Oct 2015 15:49:41 -0700
> On Oct 13, 2015, at 15:24 , Graham Cox <email@hidden> wrote:
>
> In a piece of code I haven’t worked on in a while, I’m suddenly getting a new warning which I’ve never seen before:
>
> “Multiple unsequenced modifications to ‘ix’”
>
> Code is:
>
>
> ix = ++ix % guess.count;
>
> where ix is a NSUInteger.
>
> Is this telling me that the order of the preincrement and the mod operation is undefined? Surely a preincrement is defined to happen first, that’s why it’s called a PREincrement? Or does the warning refer to something else? I’ve used this form of expression for years without any issues, why is it suddenly one?
The answer is here. It seems ridiculous, but there it is:
http://en.cppreference.com/w/c/language/eval_order#Undefined_behavior
You can read the entire page a few times to try to understand why. I still don't, and think this is counterintuitive at best, and plain wrong at worst. At least I prefer to make those kinds of things explicit anyway, and am not likely to write that code.
ix += 1;
ix %= guess.count;
hth,
--
Rick Mann
email@hidden
_______________________________________________
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