skip to Main Content

I’m using GCC as compiler. I wanted to know original form of printf function. So I found stdio.h file in /usr/include(I’m using CentOS 8.2 in GCP).

When I opened stdio.h file and found printf, something was written like

extern int printf(const char *__restrict __format, ...);

What is extern and … in this sentence? How and where can I see original form of printf function?

2

Answers


  1. extern means that the function visibility is extended to the whole program. While for the ... it represent an unspecified number of arguments for the format specifiers %d - %ld etc.. That means printf works if you want to print a string with 0 variables and with x variables, etc.

    Login or Signup to reply.
  2. What is extern and … in this sentence? How and where can I see original form of printf function?

    extern means external linkage. It tells the linker this symbol should be found in one of the objects or libraries being linked.

    There are different implementations of printf. In most cases, all printf variants, such as vprintf, fprintf etc eventually calls vfprintf. The function vfprintf itself is very complicated. Most implementations use a table-lookup method where a handler corresponding to one of the % formatters is called to format the input.

    You can see the implementation of vfprintf in glibc (one implementation of the standard library) here

    https://github.com/bminor/glibc/blob/master/stdio-common/vfprintf-internal.c

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search