C++におけるstdio.hヘッダについて
I wondered why I can use cstdio API with including only iostream.
iostreamをインクルードしただけでcstdioが使用可能になる点について疑問に思ったので調べてみました。
OSX (BSD)
I browsed c++ headers and found following path:
iostream -> ostream -> ios -> iosfwd -> wchar.h -> stdio.h
iostream -> ostream -> ios -> iosfwd -> bits/c++io.h -> cstdio -> stdio.h
iostream -> ostream -> ios -> iosfwd -> bits/postypes.h -> cwchar -> wchar.h -> stdio.h
Also I have found this very interesting path:
queue -> vector -> memory -> iterator -> iosfwd
queue -> vector -> bits/stl_algobase.h -> iosfwd
iterator -> ostream
iterator -> ostream
So, including iostream
, ios
or iterator
is enough for stdio...
Linux (glibc)
Since glibc's stdio.h is guarded, the path is little bit different.
glibcのstdio.hはガードされているので、経路は少し異なります。
# 3.3
iostream -> ostream -> ios -> iosfwd -> bits/fpos.h -> bits/c++io.h -> cstdio -> stdio.h
# 3.4,4.1,4.2
iostream -> ostream -> ios -> iosfwd -> bits/c++io.h -> cstdio -> stdio.h
# 4.3
iostream -> ostream -> ios -> bits/char_traits.h -> cstdio -> stdio.h
The path iosfwd -> bits/c++io.h
and bits/char_traits.h -> cstdio
has disappeared from g++ 4.4.
That's why we need to include cstdio separately.
iosfwd -> bits/c++io.h
およびbits/char_traits.h -> cstdio
の経路はg++ 4.4でなくなりました。
このためcstdioを別途インクルードしなければならないのです。
On the other hand,
iostream -> ostream -> ios -> __locale -> string -> cstdio -> stdio.h
this path is available (also on OSX). Really funny...
上記経路はLinuxにもOSXにも存在します。
Digression
以下余談。
MinGW
iostream -> ostream -> ios -> bits/localefwd.h -> bits/c++locale.h -> clocale -> locale.h -> stdio.h
wchar.h does not include stdio.h, but locale.h does...
Android NDK
stdio.h exists in include-fixed and it is not guarded, so the path of g++-mp-4.8 should be available. Confirmed with 4.4.3.
newlib
So firm, the implementation looks the wisest.
しっかりした作り。一番賢い実装な感じ。