*BSD News Article 17115


Return to BSD News archive

Path: sserve!newshost.anu.edu.au!munnari.oz.au!network.ucsd.edu!usc!howland.reston.ans.net!usenet.ins.cwru.edu!ljo
From: ljo@vger.eeap.cwru.edu (L Jonas Olsson)
Newsgroups: comp.os.386bsd.bugs
Subject: Re: stdio.h & __sputc problems with gcc -ansi
Date: 14 Jun 1993 14:15:32 GMT
Organization: Case Western Reserve Univ. Cleveland, Ohio (USA)
Lines: 50
Message-ID: <1vi164$hkj@usenet.INS.CWRU.Edu>
References: <1vhfrt$p3p@escargot.xx.rmit.OZ.AU>
NNTP-Posting-Host: vger.eeap.cwru.edu

In article <1vhfrt$p3p@escargot.xx.rmit.OZ.AU> zak@rmit.edu.au writes:
>
>I've discovered an annoying problem in <stdio.h> when running
>gcc (1.40 or whatever's the default) with -ansi, and a project with
>multiple .o files.
>
>When gcc gets around to linking, I get "multiply defined __sputc"
>errors (I can't remember the exact text, this is from memory).
>Looking in stdio.h, I see that __sputc is defined as 
>	static __inline
>if __GNUC__ and __STDC__ defined (i.e, gcc with -ansi.)
>Well, I can't see the problem, and there are times when I would really
>like to do `-ansi -pedantic' on a project.
>
>Got any ideas?

This bug is (was?) also present in BSDi and was detected in the
FlexFAX port.

The problem is that "inline" is not part of ansi C. Gcc defines this
macro when compiling with -ansi:
__STRICT_ANSI__

I see no reason for the __STDC__ test, do you? This stdio.h gets
included through libg++-2.*'s stdio.h when compiling C++.

The stdio.h file can be fixed with:

*** /usr/include/stdio.h~	Sat Jun  5 05:18:20 1993
--- /usr/include/stdio.h	Mon Jun 14 09:56:58 1993
***************
*** 309,315 ****
   * define function versions in the C library.
   */
  #define	__sgetc(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++))
! #if defined(__GNUC__) && defined(__STDC__)
  static inline int __sputc(int _c, FILE *_p) {
  	if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n'))
  		return (*_p->_p++ = _c);
--- 309,315 ----
   * define function versions in the C library.
   */
  #define	__sgetc(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++))
! #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
  static inline int __sputc(int _c, FILE *_p) {
  	if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n'))
  		return (*_p->_p++ = _c);

Jonas Olsson
ljo@po.cwru.edu