This is the mail archive of the guile@cygnus.com mailing list for the guile project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Hello! I have encountered a strange problem while implementing a new data structure in Guile. I have a C++ class named Coordinate, which is more or less only a structure with 3 doubles. I have installed the new datatype with the scm_newsmob function and added procedures to cope with it, which were installed with the gh_new_procedure functions. Now I have a problem with a function which should add 2 or more Coordinates. The function was installed with the command: gh_new_procedure("coordinate-add", (SCM (*) (...)) GuileCoordinateAdd, 1, 0, 1); And the function itself is looking like this: SCM GuileCoordinateAdd(SCM scm_coordinate, SCM rest_coordinates) { Coordinate * coordinate = (Coordinate *) SCM_CDR(scm_coordinate); Coordinate result = *coordinate; SCM scm_result; while(rest_coordinates != SCM_EOL) { Coordinate * arg = (Coordinate *) SCM_CDR(SCM_CAR(rest_coordinates)); result = result + *arg; rest_coordinates = SCM_CDR(rest_coordinates); } SCM_NEWCELL(SCM scm_result); SCM_SETCDR(scm_result, new Coordinate(result)); SCM_SETCAR(scm_result, type_tag); return scm_result; } Now this works well, but if I move the definition "SCM scm_result;" after the while loop the program crashed with a segmentation fault. Can anoyone explain this behavior? With best regards, Ralf Schmelter -- Ralf Schmelter Physikalische Chemie 2a Uni Dortmund 44221 Dortmund Tel.: +49 231 / 755 3942 Fax: +49 231 / 755 3937 e-mail: ralfs@heineken.chemie.uni-dortmund.de