|
Post by Walt Decker on Sept 23, 2022 14:22:58 GMT -5
LB fails to properly cast a STRUCT element of type DOUBLE and produces a non-continuable protection violation. Given: ' STRUCT tM, _ Dbl AS DOUBLE
ValIn$ = "100"
PRINT VAL(ValIn$)
tM.Dbl.struct = VAL(ValIn$) '<--- error here '
----------------------------
|
|
|
Post by Carl Gundel on Sept 23, 2022 16:44:25 GMT -5
LB fails to properly cast a STRUCT element of type DOUBLE and produces a non-continuable protection violation. Given: ' STRUCT tM, _ Dbl AS DOUBLE
ValIn$ = "100"
PRINT VAL(ValIn$)
tM.Dbl.struct = VAL(ValIn$) '<--- error here '
Interesting. It also fails with this, which is good because it would be an even stranger bug if it only failed using VAL(). STRUCT tM, _ Dbl AS DOUBLE tM.Dbl.struct = 100 '<--- error here
|
|
|
Post by Brandon Parker on Sept 24, 2022 19:06:19 GMT -5
This bug has been around for quite some time... I thought I mentioned it when I was first creating my Import Architect. Here is how I create code for LB to cast any value to a float prior to assigning it to a Struct element of type double. This type of thing is handled automatically and unseen by anyone using the Import Architect unless they examine the code produced prior to compilation using LB itself. The one-line assignment code is the exact same style code produced by the Import Architect. And, for those that might be interested, the Import Architect also provides functionality that allows the user to specify the number of decimal places used in any doubles used with a User-Defined Type. Note that this is code that is not recognized by LB itself, but is parsed by the Import Architect to produce usable LB code for a User-Type. DefineType [Node] xPos As double[5] yPos As double[5] nodeSize As short angleOfTravel As short speedX As double[5] speedY As double[5] accelerationX As double[5] accelerationY As double[5] DefineType End Obviously, there is an auto-casting issue in LB with respect to Struct elements of type double, but at least there is a way to work around it. STRUCT tM, Dbl AS DOUBLE
myVal = 100 Print myVal
tM.Dbl.struct = Val(Using(string$("#", Len(str$(myVal)));".#", myVal))
Print tM.Dbl.struct End
'____________________________________________________________________________________________________________________ '____________________________________________________________________________________________________________________
Function string$(myString$, numstring) For i = 1 To numstring string$ = string$ + myString$ Next i End Function {:0) Brandon Parker
|
|
|
Post by Walt Decker on Sept 24, 2022 19:30:03 GMT -5
Thank you, Mr. Parker. I have copied that snippet and will possibly use it in the future. I could do basically the same thing with NUMBERMAN.DLL but since I only needed 5 digits I just redefined the element as char[6].
|
|
|
Post by Brandon Parker on Sept 24, 2022 19:41:14 GMT -5
Yeah, the char[x] is another "gotcha" bit... You always have to define the char as (length_desired + 1) since LB always makes the last character chr$(0).
{:0)
Brandon Parker
|
|
|
Post by Walt Decker on Sept 26, 2022 10:40:24 GMT -5
I think that is the C designation for a fixed length string. The length of the string is actually the designated length but any text placed in it that is longer than the designated length - 1 is truncated to fixed size - 1 with the last character as NUL.
If I recall correctly C also has a variable length string designation, something like CHAR[*] StrName.
|
|
|
Post by Brandon Parker on Sept 26, 2022 21:04:44 GMT -5
Yes, it is a "gotcha", not a bug... It is one of those things that people just aren't aware of.
With respect to C, I think its implementation wholeheartedly depends on which revision the compiler follows. There have been some differences in C with respect to char[] over the years. How that might be translated through Smalltalk into LB is only a question Carl might be able to answer.
{:0)
Brandon Parker
|
|