strings initialized? - Printable Version +- Forum (https://www.boriel.com/forum) +-- Forum: Compilers and Computer Languages (https://www.boriel.com/forum/forumdisplay.php?fid=12) +--- Forum: ZX Basic Compiler (https://www.boriel.com/forum/forumdisplay.php?fid=11) +---- Forum: Help & Support (https://www.boriel.com/forum/forumdisplay.php?fid=16) +---- Thread: strings initialized? (/showthread.php?tid=252) |
strings initialized? - programandala.net - 06-18-2010 Yesterday I experienced a kind of coding poltergeist with the following simple function: Code: function strings(times as ubyte, text as string ) as string The program did strange things when printing the string returned by strings(): it printed other strings of the program that had nothing to do, and then froze. The reason was I had supposed the DIMed strings were initialized to an empty string but they are not; it took time to find out. When I added a simple line, everything worked as expected: Code: dim result as string I've searched in the forum, but found no reference about this. The DIM wiki page doesn't mention string initialitazion. I just want to confirm this issue before updating the wiki. Are strings not initialized to empty strings because of a technical issue or simply because it's not implemented yet? Is this definitive or will it change in the future? Re: strings initialized? - boriel - 06-18-2010 This might be a bug. Every uninitalized string must default to "" or NULL (they're almost equivalent for the compiler). I will test this and if so, move this topic to the Bug-Reports folder. Thanks! Re: strings initialized? - britlion - 06-18-2010 Huh. We've seen this issue before, actually. I thought this bug was killed - did some code revert? Re: strings initialized? - boriel - 06-18-2010 britlion Wrote:Huh. We've seen this issue before, actually. I thought this bug was killed - did some code revert?This is exactly what I was thinking. Anyway, everything is in the svn history :wink: Re: strings initialized? - boriel - 06-18-2010 I can't reproduce the bug. What version do you have?? Please, download latest one from the Archive and retry. You might be using an "old" (3 weeks old) version Re: strings initialized? - programandala.net - 06-19-2010 boriel Wrote:What version do you have?? Please, download latest one I had dowloaded 1.2.6r1603c some days ago, but I've just realized I hadn't updated the symbolic link to it!, so I was still using 1.2.6r1603b. Anyway I tried both, and the program crashes with both. I have just downloaded the last development version in the archive (1.2.6r1603e) and the program frozes after printing a different string, in fact a whole string array (that happened some hours ago with 1.2.6r1603b). The problematic function (the same I mentioned before) is: Code: function strings(times as ubyte, text as string ) as string And the sub that calls it is the following: Code: sub wcls() And: Code: const firstCol as ubyte = 1 Don't worry, it's not important.It will be solved by time Re: strings initialized? - boriel - 06-19-2010 Again, your code is working OK for me :!: :?: Two observations to your code:
Since your FOR loop in wcls has a *negative* STEP and lower limit is 0, this loop will run forever due to UByte overflow. The FOR l iterator needs to get a value below 0 (negative) to stop. Declaring variable l (the iterator) as Byte (signed) will solve this issue. Also, you have to define firstLine, lastLine (maybe as wcls parameters?). I used 1 and 24 respectively and it worked. Try this and tell me. |