Mail Archives: djgpp/1995/06/24/19:56:38
Your code says both:
>extern char *buf;
>char buf[BUF_SIZE];
Your code is buggy; the extern is wrong. char * and char[] are
completely different. Your extern tells gcc that "buf" is a pointer
to some data; in your case it thinks there are four bytes at address
"buf" pointing somewhere. The `buf' definition tells the compiler to
put BUF_SIZE bytes of data at `buf'. So the compiler looks at buf to
find a pointer, but actually grabs the first four bytes of the array
and treats that as a pointer!
Try "extern char buf[]". And *NEVER* put externs in C files. Always
put them in a header file seen by the C code which defines the
variable, so the compiler can warn you if you screw up and use an
extern that's dead wrong.
-Mat
- Raw text -