xsharp.eu • DEFINE typing problem
Page 1 of 1

DEFINE typing problem

Posted: Thu Jun 24, 2021 3:00 pm
by leon-ts
Hi,

If DEFINE is typed as DWORD, then when it is placed into an array of objects, it is converted to type INT.

Sample (VO dialect):

Code: Select all

STATIC DEFINE DWORD_DEFINE := 0x00000001 AS DWORD

FUNCTION Start() AS VOID STRICT

	LOCAL a AS OBJECT[]
	a := <OBJECT>{ DWORD_DEFINE }
	? a[1]:GetType():ToString() // displays System.Int32 instead System.UInt32

	RETURN
Best regards,
Leonid

DEFINE typing problem

Posted: Thu Jun 24, 2021 3:03 pm
by leon-ts
Found this issue when passing parameters to a method using reflection:
Invoke( <OBJECT>{ value1, value2, value_from_define, ... } )

DEFINE typing problem

Posted: Thu Jun 24, 2021 3:05 pm
by robert
Leonid,
This is a problem that Chris and I recently also discovered with some if the Windows SDK defines.
If you look at the app with reflector then you'll see that the DEFINE is stored as INT.
The "AS <type>" clause for DEFINES is new in X# and apparently not always processed correctly.

If you write the define as 0x00000001U then the value will be a DWORD and the element in the object array as well.

Robert

DEFINE typing problem

Posted: Thu Jun 24, 2021 3:11 pm
by leon-ts
Robert,
Thanks so much for this very important tip!

Best regards,
Leonid

DEFINE typing problem

Posted: Thu Jun 24, 2021 6:12 pm
by robert
Leonid,
I created a ticket for this:
https://github.com/X-Sharp/XSharpPublic/issues/705
Robert

DEFINE typing problem

Posted: Fri Jun 25, 2021 5:47 am
by leon-ts
Robert,
Yesterday I added U to DWORD constants, as you suggested, and my code started to work correctly. But of course, if a type is explicitly specified for DEFINE, then this is the type that should be used. Thanks again.