tags:

views:

185

answers:

3

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.

+2  A: 

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.

Matthew Flaschen
great thanks, much as i expected then. good to have it confirmed.
tjm
+1  A: 

At least as far as I know, there was no intent to change <cstdint> between TR1 and C++0x. There's no requirement for #includeing <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.

Jerry Coffin
Ah yes, sorry, didn't mean to imply that the compiler was obliged to error when adding to `std::`, but that is sort of what i said isn't it so thankyou for clearing up the ambiguity. Do you mean that adding to `std::` causes undefined behaviour though? I didn't realise that, just thought it was very bad form. good to know. Also, reading between the lines, can I safely assume that TR1 headers will not change now, while the C++0x ones obviously can (and most probably will).
tjm
The TR1 headers are what they are, and won't change. At this point, I'd be pretty surprised to see any significant changes in the C++0x headers either though -- they've already produced the "final committee draft" and closed the official comment period for C++0x, so at this point it's mostly a matter of answering all official comments, and doing final cleanup on the wording, but for the most part the *intent* of the document should stay the same -- it's just a matter of making sure it actually says what's intended.
Jerry Coffin
Thankyou, that really clears things up for me.
tjm
A: 

<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.

czchen