Bug 159563

Summary: gcc with -std=c99 option fails to find some function in "unistd.h"
Product: [Fedora] Fedora Reporter: Jianqin Qu <jqu>
Component: glibcAssignee: Jakub Jelinek <jakub>
Status: CLOSED NOTABUG QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: 3   
Target Milestone: ---   
Target Release: ---   
Hardware: i386   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2005-06-04 10:27:24 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Jianqin Qu 2005-06-04 10:08:54 UTC
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.8) Gecko/20050511 Firefox/1.0.4

Description of problem:
When you compile the following hello.c file:

#include <unistd.h>
int main(void)
{
    getdtablesize();
    return 0;
}

compile it with option:
  gcc -c -std=c99 hello.c
gives the following warning(while it should not):

hello.c: In function `main':
hello.c:8: warning: implicit declaration of function `getdtablesize'


Version-Release number of selected component (if applicable):
gcc-3.4.3-22.fc3

How reproducible:
Always

Steps to Reproduce:
1.create a file named hello.c with the above contents
2.compile it with option "-std=c99"
3.
  

Actual Results:  You got warnings like:

hello.c: In function `main':
hello.c:8: warning: implicit declaration of function `getdtablesize'




Expected Results:  You should not expect any warnings at all.

Additional info:

No. It's very easy to reproduce the bug.

Comment 1 Jakub Jelinek 2005-06-04 10:27:24 UTC
By using -std=c99, you select strict ISO C99 namespace.
getdtablesize is only provided in BSD and X/Open namespaces.
When -std=c99 is not given, the default is BSD and SVID namespace and therefore
getdtablesize has a prototype.
If you want the getdtablesize prototype provided also with -std=c99, you need
to select some namespace that includes it.  So e.g.
-std=c99 -D_GNU_SOURCE
-std=c99 -D_BSD_SOURCE
-std=c99 -D_XOPEN_SOURCE -D_XOPEN_SOURCE_EXTENDED
-std=c99 -D_XOPEN_SOURCE=500
-std=c99 -D_XOPEN_SOURCE=600
-std=gnu99
depending on which standard your program attempts to conform to.

See info libc on Feature Test Macros.