|
|
Lite-C confusion
#244186
01/03/09 04:27
01/03/09 04:27
|
Joined: Dec 2008
Posts: 43
DavidM
OP
Newbie
|
OP
Newbie
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:
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
FlorianP
Serious User
|
Serious User
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: DavidM]
#244227
01/03/09 13:04
01/03/09 13:04
|
Joined: Oct 2007
Posts: 5,211 İstanbul, Turkey
Quad
Senior Expert
|
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
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|