XSharpPublic icon indicating copy to clipboard operation
XSharpPublic copied to clipboard

Problems with signed/unsigned variables in FOR loops

Open cpyrgas opened this issue 1 year ago • 0 comments

There are no compiler warnings reported when mixing signed/unsigned vars in FOR loops Also FOR <any DWORD value> DOWNTO 0 causes an endless loop

// core dialect, no compiler options used
FUNCTION Start() AS VOID
	LOCAL dwMaxDword := UInt32.MaxValue AS DWORD
	LOCAL iMinInt := Int32.MinValue AS INT
	
	FOR LOCAL n := -1 AS INT UPTO dwMaxDword
		// never ends
		NOP
	NEXT
	
	FOR LOCAL d := 1 AS DWORD DOWNTO iMinInt
		// never ends
		NOP
	NEXT
	
	// even this never ends, because when d reaches 0 and is substracted by one, turns to MAXDWORD and the comparison to 0 always returns eual or larger)
	// is it a different problem?
	FOR LOCAL d := 2U AS DWORD DOWNTO 0U
		// never ends
		? d
	NEXT
	FOR LOCAL d := 2U AS DWORD DOWNTO 0L
		// never ends
		? d
	NEXT

cpyrgas avatar Oct 11 '24 09:10 cpyrgas