Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
3 registered members (AndrewAMD, The_Judge, Grant), 898 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Lite-C problem #288327
09/05/09 12:01
09/05/09 12:01
Joined: Jul 2005
Posts: 1,930
Austria
Dark_samurai Offline OP
Serious User
Dark_samurai  Offline OP
Serious User

Joined: Jul 2005
Posts: 1,930
Austria
Why is the following code not working:

Code:
function test(var* returns);

function main()
{
   var return_var = 0;
   test(&return_var);
   while(return_var == 0) {wait(1);}
   error("Test!");
}

function test(var* returns)
{
	wait(6);
	*returns = 1;
}



If I remove the wait(6); the code is working correctly and error("Test!"); gets executed, but with the wait(6); Lite-C gets stuck in the while loop.
Am I overlooking something??
Are addresses after a wait not valid anymore?

I'm using A7.80 and I'm sure that in older versions this was possible.

Last edited by Dark_samurai; 09/05/09 12:02.

ANet - A stable and secure network plugin with multi-zone, unlimited players, voip, server-list features,... (for A7/A8)!
get free version
Re: Lite-C problem [Re: Dark_samurai] #288352
09/05/09 14:11
09/05/09 14:11
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline
Expert
Joozey  Offline
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands
Try making the return_var global. I'm not sure, but perhaps local variable pointers are not valid after a wait frame.


Click and join the 3dgs irc community!
Room: #3dgs
Re: Lite-C problem [Re: Dark_samurai] #288353
09/05/09 14:17
09/05/09 14:17
Joined: Sep 2003
Posts: 928
Spirit Offline

Moderator
Spirit  Offline

Moderator

Joined: Sep 2003
Posts: 928
This was already discussed many times here, maybe you can do a search. Anyway, its tricky but when you think it over its logical that this cant work. Local variables are stored on the stack and the stack address is different every frame.

Your function test is correct but in the main function the local variable return_var does not have the address &return_var that it has one frame before. So you can't set variables this way. Even if it worked it would be awful programming style when variables suddenly change due to some other function that was called many frames before.

Re: Lite-C problem [Re: Spirit] #288360
09/05/09 14:59
09/05/09 14:59
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline
Expert
Joey  Offline
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
try static var return_var = 0;

Re: Lite-C problem [Re: Joey] #288366
09/05/09 15:31
09/05/09 15:31
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline
Expert
Joozey  Offline
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands
Quote:
Even if it worked it would be awful programming style when variables suddenly change due to some other function that was called many frames before.

Well, it's about the only way to have communication between multithreaded instances.


Click and join the 3dgs irc community!
Room: #3dgs
Re: Lite-C problem [Re: Joozey] #288483
09/06/09 19:28
09/06/09 19:28
Joined: Jul 2005
Posts: 1,930
Austria
Dark_samurai Offline OP
Serious User
Dark_samurai  Offline OP
Serious User

Joined: Jul 2005
Posts: 1,930
Austria
Ok this makes sence. Thanks for clearing that up!


ANet - A stable and secure network plugin with multi-zone, unlimited players, voip, server-list features,... (for A7/A8)!
get free version

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