Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 989 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Auto-initialized empty TEXT strings lack char array #351674
12/27/10 20:20
12/27/10 20:20
Joined: Dec 2008
Posts: 271
Saturnus Offline OP
Member
Saturnus  Offline OP
Member

Joined: Dec 2008
Posts: 271
According to the manual page about the strings parameter of TEXT objects, "String pointers that are not defined through the string() parameter are initialized to empty strings" (http://www.conitec.net/beta/atext-strings.htm).

However, in contrast to ordinary empty strings (e.g. STRING *str = "";), such strings don't have a char array assigned initially (str->chars == 0).

This doesn't seem to be a problem in most cases.
When such a string gets copied to another string, though, a W1501 occurs.

Perhaps this could be changed?
I think it would be more convenient if auto-initialized empty TEXT strings already had a char array assigned as ordinary empty strings do.

Code:
#include <acknex.h>

TEXT* txt =	{
	strings = 2;
	string(""); // only define the first string
}

void main () {
	printf("[0]->chars = %p\n[1]->chars = %p",
		((txt->pstring)[0])->chars,
		((txt->pstring)[1])->chars);
	
	str_cpy((txt->pstring)[0], (txt->pstring)[1]); // W1501
}



Re: Auto-initialized empty TEXT strings lack char array [Re: Saturnus] #351722
12/28/10 10:18
12/28/10 10:18
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
It's the other way around:

str_cpy((txt->pstring)[1], (txt->pstring)[0]);

http://manual.3dgamestudio.net/astr_cpy.htm

Re: Auto-initialized empty TEXT strings lack char array [Re: jcl] #351792
12/28/10 15:53
12/28/10 15:53
Joined: Dec 2008
Posts: 271
Saturnus Offline OP
Member
Saturnus  Offline OP
Member

Joined: Dec 2008
Posts: 271
Yes, it works this way because the first string is defined in the string() parameter, while the second isn't.

My point in this respect is: Shouldn't both strings behave the same, whether or not they are defined in string()?

According to the manual, strings that are not defined in string() are initialized to empty strings automatically. However, these empty strings behave slightly different than empty strings that are defined in string(), because the latter already have a char array allocated, while the former have not. I thought there shouldn't be such a difference. (It's just a minor thing, of course.)

Re: Auto-initialized empty TEXT strings lack char array [Re: Saturnus] #351807
12/28/10 17:31
12/28/10 17:31
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
Yes, an empty string is different to the string "". An empty string is a string without content, while the string "" contains one byte.

I admit that this is a not intuitive difference, but we have to live with that, as it's the way character strings are defined in C. If I would change that for text objects, we'd get all sorts of compatibility problems.


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1