are C functions declared in <c____> headers gauranteed to be in the global namespace as well as std?
Posted
by Evan Teran
on Stack Overflow
See other posts from Stack Overflow
or by Evan Teran
Published on 2010-04-06T18:51:52Z
Indexed on
2010/04/06
19:03 UTC
Read the original article
Hit count: 236
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, what you do something like #include <cstdlib>
everything (except macros of course) are declared in the std::
namespace. Every implementation that I've ever seen does this by doing something like the following:
#include <stdlib.h>
namespace std {
using ::abort;
// etc....
}
Which of course has the effect of things being in both the global namespace and std
. Is this behavior guaranteed? Or is it possible that an implementation could put these things in std
but not in the global namespace? The only way I can think of to do that would be to have your libstdc++ implement every c function itself placing them in std
directly instead of just including the existing libc headers (because there is no mechanism to remove something from a namespace). Which is of course a lot of effort with little to no benefit.
The essence of my question is, is the following program strictly conforming and guaranteed to work?
#include <cstdio>
int main() {
::printf("hello world\n");
}
© Stack Overflow or respective owner