stdio.h explanation

[green]
I'm trying to fully understand this following section in the stdio.h. My C is not as good as I would like it to be since I have been focusing on x86 assembly for around a couple years now but if someone could breakdown this little snippet of the header and explain in sort of layman terms what is being declared and why, thanks. I think I have most of it mainly, but I'm a little fuzzy on a couple of lines as I will point out below. I'll format it as a code tag for easy reading.
[/green]

[code]
/*
* The structure underlying the FILE type.
*
* I still believe that nobody in their right mind should make use of the
* internals of this structure. Provided by Pedro A. Aranda Gutiirrez
* .
*/
#ifndef _FILE_DEFINED
#define _FILE_DEFINED
typedef struct _iobuf
{
char* _ptr;
int _cnt;
char* _base;
int _flag;
int _file;
int _charbuf;
int _bufsiz;
char* _tmpfname;
} FILE;
#endif /* Not _FILE_DEFINED */

[red]I'm fuzzy on here to pretty much to the end.[/red]
/*
* The standard file handles
*/
#ifndef __DECLSPEC_SUPPORTED

extern FILE (*__imp__iob)[]; /* A pointer to an array of FILE */

#define _iob (*__imp__iob) /* An array of FILE */

#else /* __DECLSPEC_SUPPORTED */

__MINGW_IMPORT FILE _iob[]; /* An array of FILE imported from DLL. */

#endif /* __DECLSPEC_SUPPORTED */

#define stdin (&_iob[STDIN_FILENO])
#define stdout (&_iob[STDOUT_FILENO])
#define stderr (&_iob[STDERR_FILENO])

#ifdef __cplusplus [red]By the way, what does this mean?[/red]
extern "C" {[red]For disabling overloading functions maybe?[/red]
#endif
[/code]

Comments

  • i know this much:
    __imp__iob is a symbol created by dlltool containing a real pointer
    * to _iob


  • : #ifdef __cplusplus [red]By the way, what does this mean?[/red]
    : extern "C" {[red]For disabling overloading functions maybe?[/red]
    : #endif
    : [/code]
    :
    :

    You will find it's match somewhere below in that file something like this:

    #ifdef __cplusplus
    }
    #endif

    This means that the library in which those functions reside were compiled as ANSI C, and the directive informs the compiler of this. Without this directive, when compiled in .cpp the compiler will mangle the names (side effect of function overloading), and the result is those functions won't be found during link.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories