Niraj Raut
Niraj Raut

Reputation: 205

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;
}

Upvotes: 2

Views: 926

Answers (3)

Ilian Zapryanov
Ilian Zapryanov

Reputation: 1184

Probably you should add the complete function definition as supposed to be from MinGW which appears to be:

__mingw_ovr
__attribute__((__format__ (gnu_printf, 1, 2))) __MINGW_ATTRIB_NONNULL(1)
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;
}

which is is found quite different from the original GNU stdio.h found here : https://code.woboq.org/userspace/glibc/libio/stdio.h.html

Either way mingw looks like it has function definitions in header file. And if you look at #define __mingw_ovr static __attribute__ ((__unused__)) __inline__ __cdecl what __mingw_ovr is it - it appears that is an inline function.

Upvotes: 1

mlp
mlp

Reputation: 825

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.

Upvotes: 2

mutantkeyboard
mutantkeyboard

Reputation: 1724

According to C-language standard draft

7.21 Input/output

7.21.1

Introduction

1 The header defines several macros, and declares three types and many functions for performing input and output.

2 The types declared are size_t (described in 7.19);

Link -> http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1548.pdf (page - 314)

As for what the code is doing: It prints formatted data to the stream.

Upvotes: -1

Related Questions