Does the compiler provide the following functions: printf, scanf?

I'm currently learning C. This book says that "the compiler provides these library functions:" printf "," scanf "...".

I can not understand. These functions are defined in the header file <stdio.h> , right?

Why does this book explain what functions are provided by the compiler?

+4
source share
5 answers

printf , scanf , and other standard library functions are provided as part of the implementation.

The C implementation consists of several components. The compiler is one of them. The library is different; it consists of headers (usually provided as source files, such as stdio.h ) and some forms of object code files containing code that actually implements library functions.

The stdio.h header only declares these functions; he does not define them. The printf declaration looks something like this:

 int printf(const char *format, ...); 

The definition of printf is code that actually does the job of parsing a format string, accessing arguments, and sending formatted output to stdout . This is usually (but not required) written in C and provided as some kind of reference object code.

For some C implementations, the compiler and library are provided by the same organization. For others, they can be provided separately (for example, MinGW combines the gcc compiler with the Microsoft library).

+6
source

Functions are provided by the standard library, which is a collection of pre-compiled code that is usually written by the authors of the compiler (but it really is not part of the compiler itself).

Note that functions are only declared in header files. The definition is in the source files that have already been compiled.

+5
source

Saying: "The compiler provides these library functions," printf "," scanf "..", the author of the book is messy.

The standard corresponding C implementation provides declarations of these functions in header files and implementations of these functions in some library flaw. The compiler is just one aspect of the C programming environment.

+1
source

The compiler does not provide these functions. The purpose of the compiler is to translate your high-level language code into another form, in particular an executable binary.

The C standard library contains functions in stdio.h and stdlib.h.

The link compiler is a standard library with your code so that your code can call these functions. p>

For almost all libraries, you must tell the compiler which libraries you want to link. It so happened that for some compilers, the library (libc) for stdio.h and stlib.h is automatically linked without specifying them.

+1
source

These features, provided by the standard library and GCC, include built-in versions of many of the functions in the C. standard library https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html

+1
source

All Articles