Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unsequenced modification and access to parameter

I'm using open source project (NSBKeyframeAnimation) for some of animations in my p roject. Here are example of methods that i'm using:

double NSBKeyframeAnimationFunctionEaseInQuad(double t,double b, double c, double d)
{
    return c*(t/=d)*t + b;
}

I have updated my Xcode to 5.0, and every method from this project started to show me warnings like this: "Unsequenced modification and access to 't' ". Should i rewrite all methods to objective-c or there's another approach to get rid of all these warnings?

like image 533
ignotusverum Avatar asked Sep 10 '13 21:09

ignotusverum


2 Answers

The behavior of the expression c*(t/=d)*t + b is undefined, and you should fix it, e.g. to

t /= d;
return c*t*t + b;

See for example Undefined behavior and sequence points for a detailed explanation.

like image 87
Martin R Avatar answered Nov 09 '22 05:11

Martin R


those warnings can be disabled

put this before the code triggering the warning

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunsequenced"

and this after that code

#pragma clang diagnostic pop

however, nothing guarantees that compilers will always handle this case gracefully. i came to this page because i got 50 of those warnings, in exactly the same source file.

i'm grateful for those functions, but the programmer should realize that trying to write everything on one line is very "1980's", when the compilers weren't nearly as optimized as today.

and when it actually matter to win a few processor cycles, we only had a few million, not the billions we have now.

i would always put readability first.

like image 43
Pizzaiola Gorgonzola Avatar answered Nov 09 '22 05:11

Pizzaiola Gorgonzola