Gamestudio Links
Zorro Links
Newest Posts
Removing outliers from files
by AndrewAMD. 12/02/26 15:26
SGT_FW
by Aku_Aku. 11/30/26 08:19
Experiences with cTrader
by JeyKey II. 11/27/26 09:04
make a complaint
by EW_bytes. 11/26/26 23:00
FXCM => AVA Trade Plugin???
by Martin_HH. 11/25/26 21:59
No connection to MT4
by Martin_HH. 11/23/26 06:38
MinMax function on History t6 file
by LucasJoshua. 11/21/26 14:28
What are you working on?
by rayp. 11/20/26 18:10
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
3 registered members (AndrewAMD, BrainSailor, 1 invisible), 11,577 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
EvanTJ, rht, MaliceTheMaker, Haitao_Ren, JimSimons
19250 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Lite-C confusion #244186
01/03/09 04:27
01/03/09 04:27
Joined: Dec 2008
Posts: 43
D
DavidM Offline OP
Newbie
DavidM  Offline OP
Newbie
D

Joined: Dec 2008
Posts: 43
Being a C/C++/Java/D/Python programmer, Lite-C's semantics have me confused at times.

Look at the following function:

Code:
function vec_dump(STRING * name, VECTOR* vec )
{
	if ( name==NULL ) return;
	diag_var( "%s", name );
	if ( vec==NULL )  diag("NULL"); 
	else {
	diag_var(" x=%f", vec.x );
        diag_var(" y=%f", vec.y );
	diag_var(" z=%f\n", vec.z );
	}
}


void main()
{
	VECTOR foo ;
	vec_set( foo, vector(1,2,3) );
	vec_dump( "Show Me", foo );
}


The vec_dump function crashes when the passed VECTOR* is accessed.

PS. I realize I am passing a stack object(foo) to a pointer function but the manual explains Lite-C converts structs references to struct pointers.

Re: Lite-C confusion [Re: DavidM] #244190
01/03/09 06:55
01/03/09 06:55
Joined: Mar 2002
Posts: 1,774
Magdeburg
F
FlorianP Offline
Serious User
FlorianP  Offline
Serious User
F

Joined: Mar 2002
Posts: 1,774
Magdeburg
Well, the problem is not the vector - its the diag_var.
I don't really know why it crashs but e.g. diag(name); works.
I think diag_var uses c++ structs and cannot convert the gamestudio-strings


Last edited by FlorianP; 01/03/09 06:57.

I <3 LINQ
Re: Lite-C confusion [Re: FlorianP] #244220
01/03/09 12:46
01/03/09 12:46
Joined: Dec 2008
Posts: 43
D
DavidM Offline OP
Newbie
DavidM  Offline OP
Newbie
D

Joined: Dec 2008
Posts: 43
If I comment out the lines which log the vector x,y,z then the function works.

It seems to have a problem with the vector.

Re: Lite-C confusion [Re: DavidM] #244227
01/03/09 13:04
01/03/09 13:04
Joined: Oct 2007
Posts: 5,211
İstanbul, Turkey
Quad Offline
Senior Expert
Quad  Offline
Senior Expert

Joined: Oct 2007
Posts: 5,211
İstanbul, Turkey
VECTOR* foo = vector(0,0,0);
vec_set( foo, vector(1,2,3) );
vec_dump( "Show Me", foo );


3333333333
Re: Lite-C confusion [Re: Quad] #244231
01/03/09 13:24
01/03/09 13:24
Joined: Dec 2008
Posts: 43
D
DavidM Offline OP
Newbie
DavidM  Offline OP
Newbie
D

Joined: Dec 2008
Posts: 43
Thanks for the post Quad but my question is why my code doesn't work.

vector() uses a pool of 64 temporaries so it isn't always appropriate and I want a function which can dump local, global or temporaries.

Re: Lite-C confusion [Re: DavidM] #244247
01/03/09 15:49
01/03/09 15:49
Joined: Sep 2003
Posts: 938
Spirit Offline

Moderator
Spirit  Offline

Moderator

Joined: Sep 2003
Posts: 938
This is interesting, it works when I call

vec_dump( "Show Me", &foo );

as I would in C++, but lite-C is supposed to save newbies from the '&' stuff, maybe diag_var is an exception? Or it is a bug in lite-C?

Re: Lite-C confusion [Re: Spirit] #244249
01/03/09 16:01
01/03/09 16:01
Joined: Sep 2003
Posts: 938
Spirit Offline

Moderator
Spirit  Offline

Moderator

Joined: Sep 2003
Posts: 938
I have to take this back, it now crashes with &foo as well - but now I see the reason:

diag_var( "%s", name );

That's the crash. "name" is not a var, its a char* so youre passing a wrong argument type, and "%s" wont work in diag_var anyway I guess.


Last edited by Spirit; 01/03/09 16:05.

Gamestudio download | 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