Gamestudio Links
Zorro Links
Newest Posts
Free Live Data for Zorro with Paper Trading?
by dr_panther. 05/18/24 11:01
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (7th_zorro, dr_panther), 724 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 2 1 2
Re: HELP! Weird pointer declaraion behaviour needs explaning please [Re: MrGuest] #386192
10/30/11 12:56
10/30/11 12:56
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Quote:
In Lite-C the pointer star "*" belongs to the data type.

That's not correct, every lite-C data type is usually written as

BMAP* my_bmap = ...
or
TEXT* my_text = { ... }

but all it means is that you have a pointer *my_text that points to the TEXT object on the right side of the "=".


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: HELP! Weird pointer declaraion behaviour needs explaning please [Re: Superku] #386198
10/30/11 14:08
10/30/11 14:08
Joined: Apr 2009
Posts: 33
Germany
B
Bunsen Offline
Newbie
Bunsen  Offline
Newbie
B

Joined: Apr 2009
Posts: 33
Germany
You are missing the (local) inbetween assignment declaration. Try this:

Code:
void main()
{
	VECTOR v0;
	vec_set(v0, vector(1,2,3));
	
	VECTOR *v1 = &v0, *v2; // v2 is not a pointer to a vector as v1
		
	v2 = v1; // wrong
	
	while(1){
		DEBUG_VAR(v2.x, 20);
		DEBUG_VAR(v2.y, 40);
		DEBUG_VAR(v2.z, 60);
		wait(1);
	}
}



VECTOR is also not a good example because it's a typedef struct.

This runs correct because var2 is a short pointer and not a short data:
Code:
function main()
{
	short *var1 = sys_malloc(10*sizeof(short)), var2;
	
	int i;
	for (i=0; i<10; i++)
		var1[i] = i;
	
	var2 = var1; // correct
	
	printf("%d", var1[6]); 
	printf("%d", var2[6]); // Expected result "6"
}



This is wrong, because var2 becomes a pointer to a short pointer:
Code:
function main()
{
	short *var1 = sys_malloc(10*sizeof(short)), *var2;
	
	int i;
	for (i=0; i<10; i++)
		var1[i] = i;
	
	var2 = var1; // wrong
	
	printf("%d", var1[6]);
	printf("%d", var2[6]); // Not expected result "6"
}



This is correct, because var2 is handled as a pointer to a pointer:
Code:
function main()
{
	short *var1 = sys_malloc(10*sizeof(short)), *var2;
	
	int i;
	for (i=0; i<10; i++)
		var1[i] = i;
	
	var2 = &var1; // correct
	
	printf("%d", var1[6]);
	printf("%d", *((*var2) + 6)); // Expected result "6"
}



Re: HELP! Weird pointer declaraion behaviour needs explaning please [Re: Bunsen] #386221
10/30/11 22:41
10/30/11 22:41
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline OP
Expert
EvilSOB  Offline OP
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Please forgive me but my morning coffee has not reached my brain yet...

I see things here I agree with, some I dis-agree with, and some that i need to check.

BUT... The most important thing to be uncovered in this thread, I feel, was what
I discovered during my post that contains my complete test script.

And that discovery was this...
Code:
short *DATA=sys_malloc(sizeof(short)*10), *ROW;    //this line FAILS

short *DATA=sys_malloc( 4 * 10), *ROW;             //this line WORKS as I would expect




"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: HELP! Weird pointer declaraion behaviour needs explaning please [Re: EvilSOB] #386232
10/31/11 09:32
10/31/11 09:32
Joined: Apr 2009
Posts: 33
Germany
B
Bunsen Offline
Newbie
Bunsen  Offline
Newbie
B

Joined: Apr 2009
Posts: 33
Germany
@EvilSOB:

you are right! There must be a strange error with the sizeof() Macro.

This version runs correctly:
Code:
function main()
{
	int n = sizeof(short);
	short *var1 = sys_malloc(10 * n), *var2;
	// or using constants: short *var1 = sys_malloc(10 * 2), *var2;
	
	int i;
	for (i=0; i<10; i++)
		var1[i] = i;
	
	var2 = var1; // correct
	
	printf("%d", var1[6]);
	printf("%d", var2[6]); // Expected result "6"
}



where this version turns var2 into a pointer to a short pointer:

Code:
short *var1 = sys_malloc(10 * sizeof(short)), *var2;



Re: HELP! Weird pointer declaraion behaviour needs explaning please [Re: Bunsen] #386233
10/31/11 09:39
10/31/11 09:39
Joined: Feb 2009
Posts: 3,207
Germany, Magdeburg
Rei_Ayanami Offline
Expert
Rei_Ayanami  Offline
Expert

Joined: Feb 2009
Posts: 3,207
Germany, Magdeburg
There once was a similar problem...

"sizeof() is a macro and not a function. It can be used for setting a variable or passing a parameter to a function, but can not be used in expressions. Thus, long_size = sizeof(long); is ok, but long_size_times_ten = sizeof(long)*10; is not. This restriction does not apply to A7.7 or above."

Maybe that is happening again?

Re: HELP! Weird pointer declaraion behaviour needs explaning please [Re: Rei_Ayanami] #386234
10/31/11 10:35
10/31/11 10:35
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline OP
Expert
EvilSOB  Offline OP
Expert

Joined: Feb 2008
Posts: 3,232
Australia
FINALLY !! Someone agrees with me! Woohoo!

Now I feell 'validated' enough to pass ths over to the "Bug Hunt" forum.

Thanks guys...

I will post results from JCL here when I get them...

HERE is the post in Bug Hunt....



Last edited by EvilSOB; 10/31/11 10:48. Reason: Link to bug hunt added

"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: HELP! Weird pointer declaraion behaviour needs explaning please [Re: EvilSOB] #386240
10/31/11 12:13
10/31/11 12:13
Joined: Apr 2009
Posts: 33
Germany
B
Bunsen Offline
Newbie
Bunsen  Offline
Newbie
B

Joined: Apr 2009
Posts: 33
Germany
@EvilSOB:

you had better wait for some other detections (you never know, if JCL has got his dayly ration of "Frischfleisch").

This works too:
Code:
short *v1=(short*)sys_malloc(sizeof(short)*5);
short *v2;



So it would be possible, that the sizeof() Macro is working, but inbetween assignments (at least in combination
with sizeof() not.

Re: HELP! Weird pointer declaraion behaviour needs explaning please [Re: Bunsen] #386254
10/31/11 15:43
10/31/11 15:43
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline OP
Expert
EvilSOB  Offline OP
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Being added to the bug list shortly...

Originally Posted By: JCL

Yes, indeed the compiler assigns a wrong type to the second pointer, and it's indeed apparently related to sizeof() in the same line. Seems that no one has encountered this strange bug before.

It's too late for 8.30, but this will be fixed in 8.40. Until then, please don't define a pointer in the same line behind a sizeof() call.




"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Page 2 of 2 1 2

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