Home How can I ensure that all primitives are at least null-initialized in my iOS app?
Reply: 2

How can I ensure that all primitives are at least null-initialized in my iOS app?

meisel
1#
meisel Published in 2017-12-07 18:43:02Z

Under ARC, all objects are nil-initialized if they are declared but not used, but the same is not true of primitives. I'd like to trade some performance for safety and make sure that they're always initialized. Is there some flag I can pass to clang to have it nil-initialize everything by default?

Allen R
2#
Allen R Reply to 2017-12-07 18:49:47Z

There is no flag that we can pass to do this. The primitives you declare are initialized to some value when they are created, you just do not know what that value will be. You cannot set any primitive types to nil.

Here is a post that you may find helpful to understand primitives and nil better.

gnasher729
3#
gnasher729 Reply to 2017-12-07 20:31:33Z

You should switch to Swift, which will ensure that you initialise everything to something sensible.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.350866 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO