mastermagrath said:
Sorry for the possibly silly question.
Am i right in saying that the C library i use on a windows machine
really utilises the windows API for all its operations e.g. opening
files, printing to the console etc.etc.
Depends on what you mean by "all its operations".
Big parts of the C library can be implemented in a platform-independent way,
and those may use particular calling conventions but not need to defer to
any external API (or only minimally so, as in using a malloc()
implementation that calls such an API). Other parts may be
platform-dependent, but not OS-specific, like the floating-point routines
(frequently, though even here the OS may play a role).
As soon as you're talking OS-specific things, though, the library
implementation will need to depend on the API(s) provided by the OS. This
only applies if the OS is truly an OS, with hardware abstraction and memory
protection, as opposed to something like DOS, which allowed and virtually
necessitated bypassing it. (And to ward off any flames: I will readily
acknowledge that the definition of "true OS" or even just "OS" varies with
the speaker, and that there are C implementations for platforms where there
is no OS as such.)
So yes, in all likelihood, your C library on Windows will ultimately issue a
call to ReadFile() somewhere when you use fread() -- or it might use
MapViewOfFile() and read directly from memory, or maybe it uses the NT API
rather than the Win32 API, but ultimately it stops just at the point where
the OS is managing things.
It is important to keep in mind, though, that it would be a grave mistake to
conclude from this that it's "just a wrapper", and you're better off calling
the API functions directly. Not only is this not logical (since many API
functions are *themselves* wrappers), in doing so you throw away a big chunk
of portability you could have had for free, for no discernable benefit.
If you're programming in C, it's rarely a good idea to call WriteFile() on a
console handle rather than use printf(). The former will only work on Win32,
the latter on a great multitude of platforms (though not all; some systems
may not have any character output facilities).
You should consider the standard library before considering
platform-specific solutions, and even then you should take care to isolate
platform-specific code from platform-independent code. Some additional
discipline is required, but it's well worth it.
Similarly, using an (n)curses implementation for a screen-writing
application may be worth considering over calling WriteConsoleOutput()
yourself, because even if obtaining and learning such an implementation is
more work, your application will be more portable (and you learn how to
write code that works on more platforms). You may not always be able or even
willing to use libraries to increase portability, but it's worth thinking
about it.
And the reason I'm telling you all this when you didn't ask for it is
because I've seen the reverse (gratuitous dependence on platform-specific
facilities) all too often, and *especially* in Win32 programs. It's not
(semantically) wrong, but it's a darn shame.
S.