This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: What is BUFSIZ for?


On Mon, Jun 25, 2001 at 01:03:51PM -0700, Stan Shebs wrote:
> In a number of .h files, such as rtl.h and tree.h, the macro BUFSIZ
> (with no 'E') is used to ifdef prototypes for output functions,
> seemingly for anything that defines FILE *.  Presumably this is
> to ensure that stdio.h has been properly included.  My question
> is: why?  I don't see any files that include rtl.h, that are not
> part of the compiler and thus have stdio.h available already,
> and similarly for tree.h etc.  If there is a reason for this,
> then the internal docs ought to say something; the BUFSIZ tests
> are pretty weird-looking.

I dunno about weird, but section 7.19.1 in C99 (and a similar place in C89),
where it talks about stdio.h, says BUFSIZ expands to an integer constant
expression, which is the size of the buffer you pass to the setbuf function (if
you don't pass a null pointer).  So it is a standard way to test whether
stdio.h has been included.  If we didn't have to worry about pre-C89 systems,
we could just include stdio.h without any guards (since C89/C99 require that
the include file be able to be included multiple times).  However, older
systems did not have guards in them, you would get a redefinition message for
the FILE structure.  BUFSIZ has been in stdio.h in all of the public releases
of UNIX that I'm aware of (PWB, V7, etc.) after V6.

-- 
Michael Meissner, Red Hat, Inc.  (GCC group)
PMB 198, 174 Littleton Road #3, Westford, Massachusetts 01886, USA
Work:	  meissner@redhat.com		phone: +1 978-486-9304
Non-work: meissner@spectacle-pond.org	fax:   +1 978-692-4482


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]