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
4 registered members (AndrewAMD, fogman, Grant, juanex), 972 guests, and 7 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 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,209
İstanbul, Turkey
Quad Online
Senior Expert
Quad  Online
Senior Expert

Joined: Oct 2007
Posts: 5,209
İ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: 928
Spirit Offline

Moderator
Spirit  Offline

Moderator

Joined: Sep 2003
Posts: 928
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: 928
Spirit Offline

Moderator
Spirit  Offline

Moderator

Joined: Sep 2003
Posts: 928
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 | 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