Compiler switch "Initialize strings" /vo2
Posted: Thu Aug 31, 2017 9:46 am
When I found an incompatibility between our VO and X# versions of programs regarding initializing strings I looked further to the switch "Initialize strings" /vo2
It is interesting how many details may have influences when moving from Win32 to Dotnet.
I want to resume what I have found out (Surely Chris will tell if I am correct)
switch has been set to on
- All strings initially are automatically filled with "": object variables within the constructor, local variables before execution of the first line
- Comparisons with null_string are changed internally to comparisons with ""
- So comparing a string with null_string or "" returns True
- Small disadvantage: object string variables initialized before calling the super constructor are emptied again by the first constructor.
switch has been set to off
- All strings not initialized explicitly are null references to the string object
- Comparing a string "" with "" returns true and comparing with null_string returns false
- Comparing a null_string with "" returns false and comparing with null_string returns true
So it seems safe to set the switch to "On" if in an existing program there are many equal comparisons mixed with null_string and ""
Arne
It is interesting how many details may have influences when moving from Win32 to Dotnet.
I want to resume what I have found out (Surely Chris will tell if I am correct)
switch has been set to on
- All strings initially are automatically filled with "": object variables within the constructor, local variables before execution of the first line
- Comparisons with null_string are changed internally to comparisons with ""
- So comparing a string with null_string or "" returns True
- Small disadvantage: object string variables initialized before calling the super constructor are emptied again by the first constructor.
switch has been set to off
- All strings not initialized explicitly are null references to the string object
- Comparing a string "" with "" returns true and comparing with null_string returns false
- Comparing a null_string with "" returns false and comparing with null_string returns true
So it seems safe to set the switch to "On" if in an existing program there are many equal comparisons mixed with null_string and ""
Arne