are C functions declared in headers guaranteed to be in the global namespace as well as std?

后端 未结 3 545
无人及你
无人及你 2020-12-09 17:29

So this is something that I\'ve always wondered but was never quite sure about. So it is strictly a matter of curiosity, not a real problem.

As far as I understand,

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-09 18:02

    Here's a nice synopsis of the situation (with some relaity vs. what the standard says) from Stephan T. Lavavej of the MSVC team (http://blogs.msdn.com/vcblog/archive/2008/08/28/the-mallocator.aspx#8904359):

    > also, , , and std::size_t etc should be used!

    I used to be very careful about that. C++98 had a splendid dream wherein would declare everything within namespace std, and would include and then drag everything into the global namespace with using-declarations. (This is D.5 [depr.c.headers].)

    This was ignored by lots of implementers (some of which had very little control over the C Standard Library headers). So, C++0x has been changed to match reality. As of the N2723 Working Paper, http://open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2723.pdf , now is guaranteed to declare everything within namespace std, and may or may not declare things within the global namespace. is the opposite: it is guaranteed to declare everything within the global namespace, and may or may not declare things within namespace std.

    In reality and in C++0x, including is no safeguard against everything getting declared in the global namespace anyways. That's why I'm ceasing to bother with .

    This was Library Issue 456, http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#456 .

    (C++0x still deprecates the headers from the C Standard Library, which is hilarious.)

    I've never been fond of the headers myself, and found that I've always use . Now I feel like I can stop being anxious about my lack of C++ 'purity' in that regard.

提交回复
热议问题