|
Post by dragonjim on Mar 11, 2018 17:37:46 GMT 1
Just a report in case you see something similar...
I have run across a bug when passing Boolean values to an optional variant parameter in a function IF the function is called form a procedure containing a Gosub...Return structure. This is illustrated by the code examples below:
Example 1: Returns an Access Violation error – the line pointed to by the yellow arrow is ‘Return’.
trial Procedure trial Local enb As Boolean = True VarTrial(10, enb) GoSub Here Return Here: Print "Go to here" EndProcedure Function VarTrial(a%, Optional v As Variant) Print a, v EndFunction
Example 2: Where the data type of enb is changed to anything but a Boolean (in this case Int32, but Variant, Byte, Int16, etc as well), there is no error.
trial Procedure trial Local enb As Int32 = True VarTrial(10, enb) GoSub Here Return Here: Print "Go to here" EndProcedure Function VarTrial(a%, Optional v As Variant) Print a, v EndFunction
Example 3: Without the Gosub...Return construct, there is no error returned.
trial Procedure trial Local enb As Boolean = True VarTrial(10, enb) Print "Got to here" EndProcedure Function VarTrial(a%, Optional v As Variant) Print a, v EndFunction
Example 4: This does not happen if the parameter in the Function is of type Boolean
trial Procedure trial Local enb As Boolean = True VarTrial(10, enb) GoSub Here Return Here: Print "Go to here" EndProcedure Function VarTrial(a%, Optional v As Boolean) Print a, v EndFunction
|
|
|
Post by infoliner on Mar 16, 2018 19:51:53 GMT 1
Thankyou, I am using that kind of construction (with on gosub marke:) extensively, without variants but still there seems to exist a problem sometimes.
|
|
|
Post by dragonjim on Mar 17, 2018 7:57:22 GMT 1
I'm glad this proved helpful - it certainly took me a long time to work out what the problem was!
Sadly, talking to Sjouke, this appears to be a compiler bug and, as such, may not be fixed for some time to come. For that reason, if you come across any similar problems and/or workarounds, please post them here and, in the case of the former, hopefully someone may be able to offer a solution.
|
|
|
Post by infoliner on Mar 17, 2018 16:33:18 GMT 1
Yes will do so. Maybe there is also the reason hidden, why I cannot optimize when compiling, software will crash then after about 1 sec
|
|
|
Post by dragonjim on Mar 17, 2018 22:37:23 GMT 1
Have you tried the latest version of the IDE? (Look here) One of the major causes of compiler failure was fixed in that version. However, if the crash is coming about once the compiled program is run then, yes, you may be correct that it is a subtle difference. Sadly, the general advice is to skip the optimizations (some are relevant to 486/586 age CPUs but will make little difference these days; others may not be as beneficial due to the multitude of changes made to how CPUs process instructions since the GFABASIC32 compiler was last amended) - not very helpful, I know. In what area are you trying to add optimization?
|
|