Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CGFloat has weird default value

I just got confronted with very weird bug, which happened probably due to lack of my knowledge on Objective C data types. If I do this:

CGFloat newY;
NSLog(@"newY is %f", newY);

Log returns 0.0, although I would expect nil, but that's not the real problem. If I now export this app to iOS .ipa and install the app from there the newY gets automatically initialized to 185.000. Where does this value come from and why it is different when the app is installed from .ipa and not directly from XCode?

I would really appreciate any insight on what's happening, it doesn't make any sense to me.

like image 712
Igor Benko Avatar asked Jul 19 '26 01:07

Igor Benko


1 Answers

newY is not initialized to zero, it is whatever happens to be on the stack (which is where newY is stored) at the time. This may be different on different platforms but may also change between executions.

You are most likely getting a warning telling you that it is unsafe to use newY before initializing it yourself.

like image 96
Aderstedt Avatar answered Jul 20 '26 16:07

Aderstedt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!