fbpx
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: xs0030 ?

xs0030 ? 1 year 9 months ago #2699

  FFF's Avatar Topic Author FFF Away Posts: 577
Folks,
erroy xs0030: cannot convert shortint to logic.
I got this here (from Willie's rightsle):
IF !LOGIC(_And(GetKeyState(VK_SHIFT), SHORTINT(_CAST, 0x8000)))
but also in a simplified
LOCAL n := 2 AS INT
? LOGIC(n)
? (LOGIC)n

Searched through x# help for casts/conversion, but didn't find something suitable ;), VO-help as an article (Type Casting and Conversion Operators) following which i'd expect the convert to work.

Any idea (obviously i can workaround, but...)?

Karl

Please Log in or Create an account to join the conversation.

xs0030 ? 1 year 9 months ago #2700

  Chris's Avatar Chris Offline Posts: 1181
Hi Karl,

Make it a cast instead of conversion and it will work:

LOGIC(_CAST,n)

Maybe we should support also the regular conversion syntax, for the VO/Vulcan dialects, but I am not sure if allowing it is a good idea. Conversion for example from usual to logic is ok, but INT to LOGIC? With _CAST at least you denote to the compiler that you're doing that on purpose and not accidentally.

Chris
XSharp Development Team
chris(at)xsharp.eu

Please Log in or Create an account to join the conversation.

xs0030 ? 1 year 9 months ago #2701

  FFF's Avatar Topic Author FFF Away Posts: 577
Chris,
indeed, this works.
But i'm not sure, i understand the underlying logic ;)
The cited article in Vo-Help states:
...
Unlike the type conversion operators, the type casting operators change only the data type of an expression, not its value: Long(_CAST, TODAY())means take the date value Today() and use it as a long integer.
...

Doesn't that mean in my case, the compiler has to have a rule how to translate e.g. 1238 to True? And if so, why not do the conversion? A warning "implicit conversion" might be helpful.

Karl

Please Log in or Create an account to join the conversation.

xs0030 ? 1 year 9 months ago #2702

  Chris's Avatar Chris Offline Posts: 1181
Hi Karl,

In VO/win32, you can work directly with memory locations, go to any memory location and treat the contents of the bytes there (CAST them) as if it was the location where a LOGIC is stored. Or even a DATE, STRING, PSZ, anything, and that goes for both reading and writing, which is in big part responsible for many of the hard to find bugs in code that result to corrupted memory etc, this is why "unmanaged" code is considered unsafe.

In .Net, you do not work with direct memory locations, there's instead an abstraction layer, the IL language, in which you cannot do casting in the VO/c++ etc sense, only conversion. So actually the commands INT(num) and INT(_CAST,num) are translated to the exact same IL code in x# (and vulcan). We only differentiate the _CAST syntax just as an indication from the programmer to the compiler that he knows what he's doing with the data, so for example there's never overflow checking when "casting" from one numeric type to another.

About the LOGIC<->INT case, AFAIK also in VO there's no such conversion, only a cast, treating the memory location as a LOGIC or INT. As I said in .Net you cannot do that, so it's done with a conversion, but we're allowing it only with the _CAST syntax which is saying to the compiler "yes, I really want to do that, despite being a bit strange". Otherwise, if LOGIC(num) was allowed, it could very possibly just be a typo from the programmer who in fact intended to do a different "valid" conversion. So the compiler points out such possible user errors, unless the _CAST syntax is used.

Chris
XSharp Development Team
chris(at)xsharp.eu

Please Log in or Create an account to join the conversation.

  • Page:
  • 1