Reputation: 581
Since the system calls which any library function of C (say printf()) makes is OS dependant , does that imply that we have a different function printf() for different OS ?
Upvotes: 0
Views: 148
Reputation: 138051
It depends on your definition of "different", because I can think of at least three levels of difference:
The C standard suggests an interface, and this interface is supposed to be respected across the board. This means that for any OS with a C standard library, the OS should show your program an outlet called printf
, and if your program plugs into it, it can expect it to behave as documented. This means that for all you're concerned, printf
is the same across the board.
This doesn't mean that printf
has to be the same piece of code in every standard library. If someone told me to write a printf
function and told you to write a printf
function, we could have a different approach, and that would still be fine as long as we both respected the documented behavior. As a matter of fact, for copyright reasons, you can be certain that the code for Windows's printf
is different from Linux's printf
code.
And finally, even with the same source code, printf
would have to be different to accommodate platform differences. You can't expect an x86 printf
to work on ARM, for instance. And as you noted, you can't expect a Linux printf
to work on Windows because of platform conventions and system call differences.
So the machine code behind the printf
outlet will be different, but the point of the standard is to make it work the same.
Upvotes: 2
Reputation: 36401
If you mean "printf
behave differently on different OSes", then the answer is:
Upvotes: 1