Reputation: 7550
What is the difference between <cstdint>
and <tr1/cstdint>
? (apart from that one puts things in namespace std::
and the other in std::tr1::
)
Since this stuff isn't standard yet I guess it's compiler specific so I'm talking about gcc. To compile with the non-tr1 one I must compile with -std=c++0x
, but there is no such restriction when using tr1.
Is the answer perhaps that there is none but you can't go around adding things to std::
unless there, well, standard. So until c++0x is standardised an error must be issued using <cstdint>
but you dont need to worry when adding to the tr1::
namespace, which makes no claim to things in it being standard? Or is there more to this?
Thanks.
p.s - If you read "std" as standard, as I do, I do apologise for the overuse of the word in this Q.
Upvotes: 3
Views: 3246
Reputation: 5938
<tr1/cstdint>
is defined, as name suggests, in TR1, while <cstdint>
is defined in c++0x.
From gcc manual, -std=c++0x
is needed to enable experimental features that are likely to be included in C++0x. However, <tr1/cstdint>
is defined in TR1, not c++0x, so -std=c++0x
is no needed.
The following is gcc manual for -std=c++0x
for your reference.
The working draft of the upcoming ISO C++0x standard. This option enables experimental features that are likely to be included in C++0x. The working draft is constantly changing, and any feature that is enabled by this flag may be removed from future versions of GCC if it is not part of the C++0x standard.
Upvotes: 2
Reputation: 490768
At least as far as I know, there was no intent to change <cstdint>
between TR1 and C++0x. There's no requirement for #include
ing <cstdint>
to result in an error though -- officially, it's nothing more or less than undefined behavior. An implementation is allowed to specify exact behavior, and in this case it does.
Upvotes: 3
Reputation: 285077
I think you've got it. On my system, they're very similar, but with different macro logic. For instance, /usr/include/c++/4.4/tr1/cstdint
has:
# define _GLIBCXX_BEGIN_NAMESPACE_TR1 namespace tr1 {
# define _GLIBCXX_END_NAMESPACE_TR1 }
# define _GLIBCXX_TR1 tr1::
but /usr/include/c++/4.4/cstdint
has:
# define _GLIBCXX_BEGIN_NAMESPACE_TR1
# define _GLIBCXX_END_NAMESPACE_TR1
# define _GLIBCXX_TR1
So if it's being included as <cstdint>
the TR1 namespace is simply defined into oblivion.
Upvotes: 3