Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "f" stand for in C standard library function names?

Tags:

c

naming

libc

What does f stand for in the name of C standard library functions? I have noticed that a lot of functions have an f in their name, and this does not really make sense to me.

For example: fgets, fopen, printf, scanf, sqrtf and so on.

like image 298
Erik W Avatar asked Jan 14 '15 18:01

Erik W


People also ask

What is F in printf in C?

The f in printf stands for formatted, its used for printing with formatted output.

What are library functions in C?

Library functions are built-in functions that are grouped together and placed in a common location called library. Each function here performs a specific operation. We can use this library functions to get the pre-defined output. All C standard library functions are declared by using many header files.

What F stands for in printf scanf?

printf is an abbreviation for "print formatted" scanf is an abbreviation for "scan formatted"


1 Answers

Your question in general is too general but I can explain a few examples.

  • fgets, fopen, fclose, … — The ”f“ stands for “file”. These functions accept or return a FILE * pointer as opposed to a file number as the POSIX functions do.
  • printf, scanf, … — The ”f“ stands for “formatted”. These functions accept a format string.
  • fprintf, fscanf — This is a combination of the above two.
  • sinf, cosf, … — The “f” stands for float (to distinguish from the double alternatives). Note that this fits quite nicely with suffixing floating point literals with an f as in 1.5f.
  • Finally, as Deduplicator points out, there are some names such as free, floor or setbuf (“set buffer”) where the “f” simply appears as a natural language character.

The tradition of pre- or suffixing names with single letters that indicate the type of the arguments is a necessity in C that has become obsolete in C++ thanks to overloading. Actually, overloading in C++ works by the compiler automatically adding those suffixes again under the hood to the generated symbols by a process called name mangling.

like image 87
5gon12eder Avatar answered Oct 06 '22 06:10

5gon12eder