www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/06/24/19:56:38

Date: Sat, 24 Jun 95 17:24 MDT
From: mat AT ardi DOT com (Mat Hostetter)
To: M DOT Lewis AT city DOT ac DOT uk
Cc: djgpp AT sun DOT soe DOT clarkson DOT edu
Subject: Re: Bug: read( in 1.12m4 (?)
Newsgroups: comp.os.msdos.djgpp
References: <1995Jun24 DOT 185835 DOT 9998 AT city DOT ac DOT uk>

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019