char arrays

utzoo!decvax!ucbvax!unix-wizards utzoo!decvax!ucbvax!unix-wizards
Fri Dec 11 19:35:51 AEST 1981


>From decvax!duke!rjf at Berkeley Fri Dec 11 19:28:56 1981
  I've been reading the current discussions about the difference between
char foo[] and char *foo with considerable interest.  I have encountered
a somewhat similar problem lately. What happens if you declare char foo[25]
in a structure definition and then define an array of these structures?
  I did this, lint never complained, the compiler never said a word, BUT
I got bus errors and illegal instruction errors when I ran the program.
I seemed to also being destroying the stack, making adb harder to use.
  I changed the definition to char *foo in the structure definition
and in the beginning of the program called malloc to allocate the needed
amount of space for each character string for each element of the array
of structures. (Messy!) This time the program worked smoothly!
  Is the space for the char array really allocated when the space for
the structure is allocated or is space for a POINTER allocated as part
of the structure. This, I believe, is the real question. Does anyone out
there have any ideas on this?



More information about the Comp.unix.wizards mailing list