Returnvalue of uninitialized variables

This forum is meant for questions and discussions about the X# language and tools
Post Reply
ic2
Posts: 1798
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

Returnvalue of uninitialized variables

Post by ic2 »

We use a VO created function Array2String which returns an array as a delimiter separated string. In a specific situation, the array was empty which returns an empty string in VO, but apparently a nil value in X#.

I know that in .Net we are supposed to initialize all variables but in this case the compiler did not warn; by adding the 2 bold lines it works fine again. Should the compiler warn that I might return an uninitialized variable? The function does not return a proper empty string either.

Is this expected, or something we can prevent somehow? I can imagine that a lot of converted code with uninitialized variables would work in VO but not in X# as I found today.

Below the function
Dick
[hr]
Function Array2String( aArray As Array, cSep As String ) As String

Local cString As String
Local nMax, i As Dword

nMax := ALen( aArray )
For i := 1 Upto nMax
cString := cString + AsString( aArray[ i ] ) + cSep
Next i

If SLen( cString) > 0
cString := Left( cString, SLen( cString ) - 1 )
Else
cString:="" // 23-12-2021 Otherwise cString does not return the right value
Endif
Return cString
User avatar
Chris
Posts: 4562
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Returnvalue of uninitialized variables

Post by Chris »

Hi Dick,

Please enable the compiler option /vo2 ("Initialize Strings" in the Dialect page of the Project properties in VS) and it will auto initialize string vars and iVars. This option is enabled by default in all apps ported from VO (with XPorter).
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
ic2
Posts: 1798
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

Returnvalue of uninitialized variables

Post by ic2 »

Hello Chris,

I knew something was arranged for this ;) Sounds good!

The issue occurred in the X#/C# lib we use from VO, so this was not a converted program.

Dick
Post Reply