Re: 4gl and C
Posted in 1994
Oops -- I forgot to ensure that workname was pointing to valid address space... }Date: Fri Sep 2 09:56:26 1994 }From: johnl (Jonathan Leffler) }To: cwoodall@vth1.vth.colostate.edu, informix-list@rmy.emory.edu }Subject: Re: 4gl and C } }>Date: Fri, 2 Sep 1994 10:03:29 -0600 (MDT) }>From: Con Woodall <cwoodall@vth1.vth.colostate.edu> }>Subject: 4gl and C }>X-Informix-List-Id: <list.4644> }> }>A quick cry for expertise if you have been around this problem. I am }>trying to use some C functions called from 4gl. I have done this on a }>other occasions and though I am not a C programmer, what I am doing }>seems to me to be reasonably analogous to what I have done before which }>has been successful. }> }>Generally my 4gl does }> }>define p_filename char(12) }> }>call set_params(p_fieldname) }> }>The c function in question includes }> }>char *p_fieldname[12]; }> }>popquote (&*p_fieldname, 12); }> }>workname = *p_fieldname; }> }>c globals includes }> }>char *filename }> }>The failure of the call causes a segmentation fault and a core dump. I }>am also trying to decipher the dump, but I thought someone might have }>encountered the problem and see some way around it. By the way the c }>compiler does give me a warning on the "workname = *p_fieldname" saying }>that the operands are pointers to different types, but I think I might be }>stuck with this combination. I have tried a number of other combinations }>which the compiler won't let me past. }> }>Any light shed on the subject would be of benefit. } }The compiler is doing its best to tell you that your code is wrong... } }extern char *workname; Fix 1: extern char workname[]; }int set_params(i) }int i; }{ } char p_fieldname[13]; /* Note: no star! */ } /* Also note that there needs to be space */ } /* for a null terminator on the string */ } } if (i != 1) } fgl_fatal(__FILE__, __LINE__, -1318); } popquote(p_fieldname, sizeof(p_fieldname)); } workname = p_fieldname; Fix 2: strcpy(workname, p_fieldname); } return(0); }} } }Your C globals should include: } }char *workname; Fix 3: char workname[13]; }or you need to fix set_params() to refer to filename instead of workname. If you don't do this, you set workname to point to the local variable p_fieldname, which immediately goes out of scope and is overwritten by subsequent function calls. Therefore the string you thaought was saved is not saved, leading to disasters. Yours, Jonathan Leffler (johnl@informix.com) #include <disclaimer.h>