From: Shashank Date Date: 2005-01-27T05:26:49+09:00 Subject: Re: Debugging C Extensions and [A bit OT] general C Questions Hi Brian, --- Brian Schr�der wrote: > Hello Group, > > I'm right now learning to write C extensions and it > works quite good. The only problem is, that my C was > never very profound and I seem to have forgotten all > of it in the meantime. So obviously I write a lot of > bugs. The question is, how do I debug them. > > Right now I'm using printf to output things to the > console, That is how I debug all my C code :-) > but I'd rather like to debug the process in > somethink like ddd. Is this possible? Yes, I have done that too, although not with ruby-extensions. > I tried to connect to the running process, but it > said to me that the process was "no program". > > And now the OT question: > > anybody knows of a compact C manual on the web, > where I can for example learn how in this code: > > /* Structure containing the volume data */ > typedef struct { > unsigned long width, height, depth, length; > double *data; > } SRVolume; > > /* Create a new SRVolume Datastructure, initialized > to size 0x0x0 > * Is this allocation method correct, or am I > copying the data onto the > * stack and back? > */ > SRVolume rvAlloc() { > SRVolume *result = calloc(1, sizeof(SRVolume)); > result->data = calloc(0, sizeof(double)); > return(*result); > } > > the result data data is returned? Yes. I'm in the habit of type casting the calloc, like so: SRVolume *result = (SRVolume *)calloc(1, sizeof(SRVolume)); which, if nothing else makes my compiler happy ;-) > I'd think that > there is no copying of large amounts of data > involved, Correct. Only the pointer is copied. I would check to make sure that it did not return a NULL. > but I'm not 100% shure because I haven't > found a good manual explaining this yet. Have you tried this: http://www.eskimo.com/%7escs/cclass/krnotes/top.html > Additionally I get under special circumstances > (Creating a volume, setting a value and using > p(volume)) the message that it tries to free a wrong > pointer. What is p(volume) ? Is it in Ruby or C? > If i change p(volume) to puts volume.inspect ... looks like it is in Ruby. > it works. This is shurely not enough > description, but maybe you could point me to some > more information on the GC and other things that can > bring forth this error message. Can you show us some more code surrounding it? HTH, > Best regards, > > Brian -- shanko __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com