Also sprach Berkeley Hynes:
[...]
> Part of the code defining some of the variables of one of the functions is
> as follows:
>
> datum key;
> datum key1;
> datum key2;
> datum key3;
> datum content;
> datum content1;
> datum content2;
> datum content3;
This should be
struct datum key;
struct datum key1;
...
>
> where datum is defined in the gdbm.h include file as :
> struct{
> char *dptr;
> int dsize;
> } datum
This should be
struct {
char *dptr;
int dsize;
} datum;
Note the terminating semicolon.
> However, the program constantly causes segmentation faults. Examining the
> program using gdb (after compiling with "gcc prog.c -lgdbm -ggdb") reveals
> that key, key1, key2, key3, content, and content2 are all fine. ie. using
> "display content" in gdb returns:
> content={dptr=0xbffffa7c "0", dsize = 1}
> However, using "display content1" in gdb reveals:
> content1={dptr= 0x0, dsize =-1073743240}
> and similarly for content3. And the program causes the segementation fault
> at the line which calls content1 for the first time.
My guess, and it's just a guess without seeing the relevant code, is that
you are failing properly to initialize the struct's members.
>
> >From experience programming on other operating systems which shall remain
> anonymous, I figure I need to swtich to a larger memory model, or something
> else to allow gcc to allocate memory to content1 and content3 but nothing in
> the info, man, or other linux programming books tells me how to do this. Of
> course, this preliminary diagnosis could be entirely wrong...
No such thing as "memory models" under Linux. It is an abomination that
32-bit flat memory layouts nicely avoid.
> I'm sorry for taking up so much bandwidth with this question, but the fact
> that out of 8 identical variable declarations 6 were fine and 2 were not is
> exceedingly puzzling -- normally things either always work or never work...
Post the smallest complete code sample that illustrates the bad behavior.
It is difficult to diagnose otherwise.
Kurt
--
The three questions of greatest concern are -- 1. Is it attractive?
2. Is it amusing? 3. Does it know its place?
-- Fran Lebowitz, "Metropolitan Life"