Search code examples
cstdio

stdio.h contains definition or declaration of functions?


I read that the stdio.h header file contains function declarations (with prototypes), macro definitions and definitions of data types. But when I opened the file in VSCode it contained function definitions too — not sure if they are definitions or something else. Please explain the following. What is this code doing? More importantly, is it function definition?

mingw_stdio_redirect

int fprintf (FILE *__stream, const char *__format, ...)
{ 
    register int __retval;

    __builtin_va_list __local_argv; __builtin_va_start( __local_argv, __format );

    __retval = __mingw_vfprintf( __stream, __format, __local_argv );

    __builtin_va_end( __local_argv );

    return __retval; 
}

mingw_stdio_redirect

int printf (const char *__format, ...)
{
    register int __retval;

    __builtin_va_list __local_argv; __builtin_va_start( __local_argv, __format );

    __retval = __mingw_vprintf( __format, __local_argv );

    __builtin_va_end( __local_argv );

    return __retval;
}

Solution

  • The code you have quoted appears to be definitions of functions.

    Header files that you create should contain only

    • definitions of macros
    • definitions of structures, unions, and typedef-names
    • declarations of variables
    • declarations of functions, in the form of prototypes

    Later (once your C skills have advanced somewhat) you might also include

    • definitions of inline functions

    A compiler implementer, on the other hand, may put anything they like in their header files, as long as their compiler behaves the way the language standard says it must. You should rely only on the compiler's documentation, and not on anything you might intuit from reading other files supplied with the compiler, to understand its behaviour.

    A compiler implementer is permitted to use any magic they choose, including having the compiler Just Know what the system headers are required by the Standard to define and declare without any actual files for those headers, and if they so choose they may even provide "header" files containing bogus or misleading contents.