Page 1 of 1

5.40 possible string issue

Posted: Thu Nov 05, 2015 7:50 am
by Michael Vogel
I had a weird problem yesterday as a windows caption text has not been displayed in certain cases. It took me a while to recognize, that a defined string (Info(1) in the example below) seems to be converted to a null string. As soon I changed one of the double spaces at the end of the string, it has been displayed.

I made the small code example below to show that (the debugging window showed the values for Info(0) and Info(2) but an empty line for Info(1)). After changing the compiler setting to create an unicode exe, all text has been displayed fine.

This morning I restarted the PB5.40 IDE and checked, if the problem is still seen, but now I can't reproduce the issue anymore. So maybe it had soemthing to do with the planets constellation or whatever. Anyhow it could be that there's a bug somewhere (in the editor of the IDE?) which is responsible for this, so if anyone observes something like that, try to peek for more information...

Code: Select all

Global Dim Info.s(3)

Info(0)="R U N N I N G  - "
Info(1)="R U N N I N G  -  "
Info(2)="R U N N I N G -  "

Debug info(0)
Debug info(1)
Debug info(2)

Re: 5.40 possible string issue

Posted: Mon Nov 16, 2015 3:28 pm
by Fred
I can't see any issue here, can anybody else confirm ?

Re: 5.40 possible string issue

Posted: Mon Nov 16, 2015 4:39 pm
by NicTheQuick
No bug here.
Tested on Windows 7 x64 and Ubuntu 14.04 x64 with latest PB 5.40

Re: 5.40 possible string issue

Posted: Mon Nov 16, 2015 4:50 pm
by Little John
No bug here with PB 5.40 LTS x86 and x64 on Windows 10 Pro.

Re: 5.40 possible string issue

Posted: Mon Nov 16, 2015 7:44 pm
by acreis
Well ...

What am I doing wrong?

Code: Select all

EnableExplicit

Global pi.f = 3.14

Global *pi.float = @pi

Debug *pi\f ; Prints 3.14000010490417


Global title$ = "Window"

Global *Title.string = @Title$

Debug *Title\s ;Invalid memory access

Re: 5.40 possible string issue

Posted: Mon Nov 16, 2015 8:18 pm
by GPI
When you look in the manual - the string pointer is special. it is a pointer to a pointer. But with @string$ you got the pointer to the value direct.
http://www.purebasic.com/documentation/ ... emory.html
Pointers and character strings

All variables have a permanent size in memory (2 bytes for Word, 4 bytes for a Long, etc.) except for strings variables with lengths that can change. So string variables are managed by a different way of other variables.
Thus a structure field, that makes reference to a string, store only the memory address of the string instead of the string itself: a such structure field is a pointer towards a string.

Example

Text$ = "Hello"
*Text = @Text$ ; *Text store the address of the string in memory
*Pointer.String = @*Text ; *Pointer points on *Text
Debug *Pointer\s ; Display the string living at the address stored in *Pointer (i.e. @Text$)

Re: 5.40 possible string issue

Posted: Mon Nov 16, 2015 11:30 pm
by acreis
Hi GPI,

The old manual trick!

That's the second time I've fallen for that week!

I'm sorry about my mistake and thank you!!!

Re: 5.40 possible string issue

Posted: Tue Nov 17, 2015 8:01 am
by helpy
Michael Vogel wrote:... that a defined string (Info(1) in the example below) seems to be converted to a null string. As soon I changed one of the double spaces at the end of the string, it has been displayed.

...

This morning I restarted the PB5.40 IDE and checked, if the problem is still seen, but now I can't reproduce the issue anymore.
I had a similar problem some weeks ago!
A string inside a structure was empty after assigning the content of a local (protected) string variable (definitively not empty).
I debugged it several times and could not find the reason.

After restarting the IDE this issue was gone and could not be reproduced.

cu,
guido

Re: 5.40 possible string issue

Posted: Wed Nov 18, 2015 10:05 am
by Michael Vogel
helpy wrote:I had a similar problem some weeks ago!
Must be a rare one - I tried hard to reproduce this, but never had this issue again...