1

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?

meisel
  • 2,151
  • 2
  • 21
  • 38
  • from apple docs-: If your custom type has a stored property that is logically allowed to have “no value”—perhaps because its value cannot be set during initialization, or because it is allowed to have “no value” at some later point—declare the property with an optional type. Properties of optional type are automatically initialized with a value of nil, indicating that the property is deliberately intended to have “no value yet” during initialization. – Tushar Sharma Dec 07 '17 at 18:50

2 Answers2

1

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.

Nordeast
  • 1,353
  • 13
  • 21
-2

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

gnasher729
  • 51,477
  • 5
  • 75
  • 98