2

I wrote my first C program which is the generic "hello world" program. Could anyone please tell me where can I find stdio.h file in my system? It will help me a lot in understanding of the language.

2
  • 2
    Do you want to locate the file to look at it, or do you have some other issue relating to not finding it? Commented Feb 4, 2021 at 8:17
  • 2
    I very much doubt reading the system header files will be of much use to a normal user. There's too much compatibility stuff there, for different systems and settings. Also, the header file doesn't contain the implementations of the library functions themselves, it's just the function declarations etc. If you want to see the implementations, I suggest you start with some alternative, more minimal C library, instead of glibc. (I think uclibc and musl are the two.) Commented Feb 4, 2021 at 8:25

2 Answers 2

4

In Ubuntu, which your original question indicated you’re using, the “root” stdio.h file is in /usr/include. Other systems may put it elsewhere, and in all cases it’s likely that stdio.h pulls in other files.

You’ll probably find it more helpful to read the POSIX specification for stdio.h, and then look at how your system implements that. On Linux, man 3 stdio also provides a useful summary; other systems have similar documentation.

0
2

It's system-dependent (note that POSIX does not specify location of header-files, nor does the C standard). Conventionally, it would be found in /usr/include. However, on some systems (even those having a /usr/include directory), it may not be found there.

For instance, recent (the past few years) macOS SDKs put this in a directory under the SDK (just like Visual Studio...). Looking for stdio.h on one of my machines gives this list for example:

/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/usr/include/stdio.h
/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/usr/include/sys/stdio.h
/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk/usr/include/stdio.h
/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk/usr/include/sys/stdio.h
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/DriverKit19.0.sdk/System/DriverKit/usr/include/stdio.h
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/sys/stdio.h
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/stdio.h
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/stdio.h
/Applications/Xcode.app/Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS.sdk/usr/include/stdio.h
/Applications/Xcode.app/Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS.sdk/usr/include/sys/stdio.h
/Applications/Xcode.app/Contents/Developer/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator.sdk/usr/include/stdio.h
/Applications/Xcode.app/Contents/Developer/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator.sdk/usr/include/sys/stdio.h
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/stdio.h
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/sys/stdio.h
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include/stdio.h
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include/sys/stdio.h
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/stdio.h
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/sys/stdio.h
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/stdio.h
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/stdio.h
/Library/Developer/CommandLineTools/usr/include/c++/v1/stdio.h
/opt/local/include/gcc/c++/tr1/stdio.h
/opt/local/include/gcc8/c++/tr1/stdio.h
/opt/local/include/gcc9/c++/tr1/stdio.h
/opt/local/include/isc/stdio.h
/opt/local/lib/gcc8/gcc/x86_64-apple-darwin18/8.3.0/include/ssp/stdio.h
/opt/local/lib/gcc8/gcc/x86_64-apple-darwin18/8.3.0/include-fixed/stdio.h
/opt/local/lib/gcc9/gcc/x86_64-apple-darwin18/9.2.0/include/ssp/stdio.h
/opt/local/lib/gcc9/gcc/x86_64-apple-darwin18/9.2.0/include-fixed/stdio.h
/opt/local/libexec/llvm-9.0/include/c++/v1/stdio.h
/opt/local/libexec/llvm-9.0/lib/c++/v1/stdio.h

The files under /opt are for MacPorts (a third-party).

Even when the file is in /usr/include, most of its content (implementation details) may be in another file. The internal-details may be in a subdirectory of /usr/include (Solaris), or they may not (usually not). Again, macOS is an example, but there are others. Without details on the system involved, no one can give a detailed answer.

Usually (again, not always), your compiler and its associated C preprocessor can help find the actual file which is used. You'll have to consult the appropriate documentation, but this worked for me with macOS for the hello-world program:

/usr/bin/clang -E hello.c >hello.log

which (is a little too long for an answer) begins thus:

# 1 "hello.c"
# 1 "" 1
# 1 "" 3
# 366 "" 3
# 1 "" 1
# 1 "" 2
# 1 "hello.c" 2
# 1 "/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/stdio.h" 1 3 4
# 64 "/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/stdio.h" 3 4
# 1 "/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/_stdio.h" 1 3 4
# 68 "/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/_stdio.h" 3 4
# 1 "/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/sys/cdefs.h" 1 3 4
...
0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.