Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between cstdint and tr1/cstdint

Tags:

c++

c++11

tr1

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.

like image 336
tjm Avatar asked Jun 28 '26 21:06

tjm


2 Answers

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.

like image 122
Jerry Coffin Avatar answered Jun 30 '26 12:06

Jerry Coffin


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.

like image 32
Matthew Flaschen Avatar answered Jun 30 '26 11:06

Matthew Flaschen