Paolo Bonzini wrote: > On 11/11/2009 12:58 AM, Roland Plüss wrote: >> char buffer[ 50 ]; >> sprintf( ( char* )&buffer, "(%f,%f,%f,%f)", csobject.color.r, >> csobject.color.g, csobject.color.b, csobject.color.a ); >> return gst_string_to_oop( buffer ); >> >> Returns garbage in smalltalk ( function returns OOP by the way and is >> mapped with #smalltalk as return value ). As I get from the >> documentation this function only "maps" the string and does not make a >> copy. > > No, that's not true. I think you are overrunning the buffer (besides, > (char*)&buffer is simply "buffer"). Try asprintf, like Nope. The signature of sprintf is "int sprintf(char *str, const char *format, ...)". buffer thought is of type "char (*)[50]". C++ is not going to compile ( error: cannot convert 'char (*)[50]' to 'char*' for argument '1' to 'int sprintf(char*, const char*, ...)' ). Hence the type cast is required to get a proper and correct code which is accepted by a strict compiler. Another solution would be "sprintf( &buffer[0], ... )" which is again valid since &buffer[0] is of type "char*". I prefer though myself the cast solution.
Otherwise I got it working now. Didn't pay attention that smalltalk works with double instead of float. So a prior cCall involving a float messed things up as smalltalk wrote a double over a float somewhere. Changing that fixed it so no overrun in that one. I'm though most probably going to change the code anyways to use a static allocated buffer somewhere for formating. Prevents wasted allocations ( asprintf not an optimal solution ). -- Yours sincerely Plüss Roland Leader and Head Programmer - Game: Epsylon ( http://epsylon.rptd.ch/ , http://www.moddb.com/games/4057/epsylon ) - Game Engine: Drag(en)gine ( http://dragengine.rptd.ch , http://www.moddb.com/engines/9/dragengine ) - Normal Map Generator: DENormGen ( http://epsylon.rptd.ch/denormgen.php )
signature.asc
Description: OpenPGP digital signature
_______________________________________________ help-smalltalk mailing list [email protected] http://lists.gnu.org/mailman/listinfo/help-smalltalk
