How to force value initialization for POD types in Visual C ++ without changing the code?

Is there a way to force initialization of pod types to 0\false\nullptr in Visual C ++ release mode?

To be more specific, I don't want to change my code, just compile it using pod types initialized to 0\false\nullptr.

I want this because I want our system to be deterministic.

+4
source share
1 answer

Yes, initializing the value will do this.

 struct pod { int a, b; char c; double d; }; pod myPod = pod(); // Value-initialized, all members are 0. 

C ++ 11 will also allow you to assign default values ​​in a class definition, but Visual Studio does not yet support this.

 struct pod { int a = 0, b = 0; char c = 0; double d = 0.0; }; pod myPod; // All members would be initialized to 0. 
+5
source

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


All Articles