Basically, cout is defined in iostream header which is part of c++.I want to know how does this take into account the OS dependent system call interface?
Asked
Active
Viewed 51 times
0
-
Those are Implementation details... You would have to be more specific about which implementation you're asking. GCC, Clang or MSVC etc. – Jason Dec 19 '22 at 14:00
-
The C and C++ Runtime Support libraries have to be ported to each supported platform. Part of the porting is to change all the system calls to be correct for that platform. – Richard Critten Dec 19 '22 at 14:03
-
@Richard Critten does this mean that the source code of iostream header would vary according to the OS? – Dumb_Pegasus Dec 19 '22 at 14:06
-
headers specify interface, not implementation. – stark Dec 19 '22 at 14:08
-
@stark Templates laugh at that ideal. – Shawn Dec 19 '22 at 14:10
-
Take opening a file, on MS-Windows the native API is `CreateFileW` on Unix like system it will be different. So if you trace `std::fopen` down through the implementation layers you would come to the native call. Whether this is conditionally compiled or not depends on if the tool-chain vendor supports multiple platforms. – Richard Critten Dec 19 '22 at 14:10
-
@Dumb_Pegasus Yes it does. It will likely vary according to the compiler as well. – john Dec 19 '22 at 14:20
-
@Dumb_Pegasus: In theory contents of iostream header could vary according to the OS; but in practice an (portable) implementation likely uses the exact same "layers of fluff" for every OS where the only thing that's system specific is a final low level `write()` system call underneath all the layers. – Brendan Dec 19 '22 at 15:10
-
Right, thanks Richard, John and Brendan. This explains it – Dumb_Pegasus Dec 19 '22 at 15:48