DEFINE typing problem

This forum is meant for questions and discussions about the X# language and tools
Post Reply
leon-ts
Posts: 429
Joined: Fri Feb 03, 2017 1:43 pm

DEFINE typing problem

Post 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
Best regards,
Leonid
leon-ts
Posts: 429
Joined: Fri Feb 03, 2017 1:43 pm

DEFINE typing problem

Post by leon-ts »

Found this issue when passing parameters to a method using reflection:
Invoke( <OBJECT>{ value1, value2, value_from_define, ... } )
Best regards,
Leonid
User avatar
robert
Posts: 4264
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

DEFINE typing problem

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
leon-ts
Posts: 429
Joined: Fri Feb 03, 2017 1:43 pm

DEFINE typing problem

Post by leon-ts »

Robert,
Thanks so much for this very important tip!

Best regards,
Leonid
Best regards,
Leonid
User avatar
robert
Posts: 4264
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

DEFINE typing problem

Post by robert »

Leonid,
I created a ticket for this:
https://github.com/X-Sharp/XSharpPublic/issues/705
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
leon-ts
Posts: 429
Joined: Fri Feb 03, 2017 1:43 pm

DEFINE typing problem

Post 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.
Best regards,
Leonid
Post Reply