P.J. Plauger said:
James Kanze said:
P.J. Plauger said:
[...]
Btw, I have noticed that neither gcc nor VC++ require you
to write it like "std::size_t", but just "size_t" is ok
(without any 'using'). Is this also standard?
No.
It will be in C++0X, because it is de facto a widespread practice
in C++98.
It's the case in C++ 98 as well if you include <stddef.h>,
rather than <cstddef>.
My own rule to date has been to only use the .h forms of the
C headers, since I know what I'm getting with them.
Probably not, but I feel like I do
. They are, after all, the
C headers, and I know what C gives me. (I guess I think of them
more or less like I think of the Posix headers: something
outside of the language, defined in C.)
The C++ Standard says that the *.h forms must
declare all names in namespace std, then hoist them to the global
namespace with individual using declarations. A few meticulous
implementations do this, but most leave the *.h forms in their
traditional forms as inherited from older C compilers. So when
you include <stdio.h> you *might* get std:
rintf and printf,
or you *might* get just printf.
[pjp] Not all implementations, but most do. We can configure
our headers to fully conform or work the way our compiler
vendor customers want. Guess which way we choose.
I can imagine.
In practice, I'm used to writing time(NULL), and not
std::time(NULL). So the risk of accident is greater if I choose
the std:: forms---I'm likely to accidentally fall back into my
old habits. If I can count on at least one of my compilers
complaining, immediately, fine; I'll quickly adjust. If I
can't, the error is likely to persist. And while I've not tried
lately, the last time I tried, neither Sun CC nor g++ (under
Solaris) complained. I've long argued that we should also have
Comeau with your library on hand, even if only as a double check
measure, but management here finds that needing to support two
compilers is already one too many.
-- If you want to assuredly declare printf, include <stdio.h>
(but you might also declare std:
rintf).
-- If you want to assuredly declare std:
rintf, include
<cstdio> (but you might also declare printf).
In other words, and implementation is allowed to make them the
same, but it could also implement them so that the intersection
is only the macros.
That happens to reflect the reality of *all* existing
implementations, so the next C++ Standard will actually
codify existing practice instead of trying to dictate a
practice that most vendors found they could not comply
with.
I'm not sure I like this. It means that there is still one more
thing that might work with some compilers, but not with others.
If I had my druthers, the committee would just require that both
the declarations with and without std:: be available in both
headers: that shouldn't break any existing code (or at least no
more that the current proposal would break, since that would be
a legal implementation under the current proposal), and would
mean that if it compiles with one implementation, it should
compile with all.