5.40 possible string issue

Just starting out? Need help? Post your questions and find answers here.
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

5.40 possible string issue

Post 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)
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: 5.40 possible string issue

Post by Fred »

I can't see any issue here, can anybody else confirm ?
User avatar
NicTheQuick
Addict
Addict
Posts: 1504
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: 5.40 possible string issue

Post by NicTheQuick »

No bug here.
Tested on Windows 7 x64 and Ubuntu 14.04 x64 with latest PB 5.40
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
Little John
Addict
Addict
Posts: 4779
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: 5.40 possible string issue

Post by Little John »

No bug here with PB 5.40 LTS x86 and x64 on Windows 10 Pro.
acreis
Enthusiast
Enthusiast
Posts: 204
Joined: Fri Jun 01, 2012 12:20 am

Re: 5.40 possible string issue

Post 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
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Re: 5.40 possible string issue

Post 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$)
acreis
Enthusiast
Enthusiast
Posts: 204
Joined: Fri Jun 01, 2012 12:20 am

Re: 5.40 possible string issue

Post 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!!!
User avatar
helpy
Enthusiast
Enthusiast
Posts: 552
Joined: Sat Jun 28, 2003 12:01 am

Re: 5.40 possible string issue

Post 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
Windows 10 / Windows 7
PB Last Final / Last Beta Testing
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: 5.40 possible string issue

Post 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...
Post Reply