IPhone - various logical defaults on the device

I recently had some code that worked great on a simulator and twisted the device. What for? β€œIt is very simple, but I cannot explain this explanation.”

I did a little testing by creating a new application based on the view, added a shortcut and a socket for the tag, and wrote this code in viewDidLoad:

BOOL b; if (b) { label.text = @"Value = YES"; } else { label.text = @"Value = NO"; } 

Interestingly, here are the results:

iOS Simulator (4.2): Value = NO
iOS Simulator (4.3): Value = NO
iPod Touch 2G (4.2.1) Value = YES
iPhone 3G (4.2.1)) Value = YES

What does that say? - Well, for me it looks like devices, the default logical value is YES, and on the simulator the default value is NO.

Can anyone clarify if this is so? Also, if someone can explain this behavior, I would be very interested.

I am not interested in solving the problem, so it can be solved by setting the desired default (in my case NO ) manually.

Thanks.

+4
source share
2 answers

Objective-C is simply a superset of C, and in C declaring such a variable, it simply gives it memory on the stack. The variable is not set in anything when it is declared, so everything that was last on the stack is now in your variable b .

In short, it is undefined and will differ from implementation to implementation. This is what the spec says.

+5
source

Undefined behavior is undefined.

+4
source

Source: https://habr.com/ru/post/1383111/


All Articles