I found that in C99 you should #include <stdint.h>
and that seems to work with my C++03 gcc compiler too, but is that the right header for modern C++, is it portable?
Asked
Active
Viewed 2.6k times
23
-
`#include
` or `#include – obataku Sep 01 '12 at 13:59` -
2-1: for not bothering to look it up in the [easily searchable online references](http://en.cppreference.com/w/cpp/types/integer). – Nicol Bolas Sep 01 '12 at 14:11
-
8I think the objective is to have questions answered on stackoverflow, just because information can be Googled, does not mean a question is not worth having, or have I misunderstood the purpose of this site? – WilliamKF Sep 01 '12 at 14:14
-
@WilliamKF: That is true, but at the same time, it is also true that you have not tried anything yourself. Just because you don't know something, doesn't mean that you *must* ask others, without *first* trying to find out the answer yourself. Asking others what you don't know, must not be programmers's habit. You must try yourself first. – Nawaz Sep 01 '12 at 14:16
-
1But I did try it myself, I got my application to work and then posted the question *and* the answer that worked for me at the same time to help the next person. I don't feel like I was being lazy but attempting to assist the next person. Is my behavior really something to be discouraged? – WilliamKF Sep 01 '12 at 14:20
-
3@Nawaz respectfully, I believe there is evidence on this page contrary to what you say of WilliamKF and his motivations. – Drew Dormann Sep 01 '12 at 14:22
-
@WilliamKF: The question doesn't say anything about your efforts which you invested to find out the answer. Anyone reading your question would feel that you have not tried anything yourself. – Nawaz Sep 01 '12 at 14:25
-
1I've updated the question to include what my efforts had revealed to be the answer. Let me know if that is more in line with the expected style here, thanks! – WilliamKF Sep 01 '12 at 14:29
-
@WilliamKF: It is still poor. I don't see any problem description which you face with what you found yourself. – Nawaz Sep 01 '12 at 14:36
-
@DrewDormann: I don't see any evidence. What evidence you're talking about? – Nawaz Sep 01 '12 at 14:37
-
1@Nawaz The issue I faced was I wanted to use the `uintptr_t` type and needed the correct header file to include. I found the answer to be `stdint.h`. Perhaps this question should be deleted because it is not considered helpful to others? My sense was that it would be helpful, but if others disagree then let's delete it. – WilliamKF Sep 01 '12 at 14:40
-
@WilliamKF: You still didn't understand my point! – Nawaz Sep 01 '12 at 14:45
-
1@Nawaz Sorry for being dense, please elaborate so I can better appreciate your point. – WilliamKF Sep 01 '12 at 14:47
-
@Nawaz: I'm sorry, but I do not wish to continue this. – Drew Dormann Sep 01 '12 at 14:48
-
2@Nawaz: (and anyone) Feel free to continue the discussion here: http://meta.stackexchange.com/questions/145644 – Wesley Murch Sep 01 '12 at 14:50
-
@WilliamKF: My previous comment says : *"I don't see any problem description which you face with what you found yourself"*. I think that tacitly asks you something. – Nawaz Sep 01 '12 at 14:51
-
Revision 6 of this question is quite acceptable as a SO question. Upvoted. – Pascal Cuoq Sep 01 '12 at 16:26
5 Answers
21
In C++11, it's in <cstdint>
.
In older versions of the language, it didn't officially exist; but many compilers provided the C99 library as an extension, in which case it would be available in <stdint.h>
.

Mike Seymour
- 249,747
- 28
- 448
- 644
4
It is defined in stdint.h:
#include <stdint.h>

WilliamKF
- 41,123
- 68
- 193
- 295
-
1That header exists for backwards-compatibility with C. It _will_ define `uintptr_t` in the global namespace, but not `namespace std`. You can expect all standard headers that end in `.h` to be namespace-unaware. – Drew Dormann Sep 01 '12 at 14:15
-
-
1@DrewDormann - they aren't necessarily unaware of namespaces. The standard C headers are required to put their names in the global namespace, and they are permitted to put them in `namespace std`. Similarly, the C++ analogs of the C headers are required to put their names into `namespace std` and are now allowed to put them in the global namespace, as well (that's a bow to existing implementations). – Pete Becker Sep 01 '12 at 14:39
2
Include either cinttypes
or cstdint
.

obataku
- 29,212
- 3
- 44
- 57
-
`
` doesn't define `uintptr_t`. Mostly it defined macros that can be used as format specifiers for the types defined in ` – Pete Becker Sep 01 '12 at 14:44` when using `printf` and `scanf` and their brethren. -
1
0
It's in C99, in , as an optional type. Many C++03 compilers do provide that file. It's also in C++11, in , where again it is optional, and which refers to C99 for the definition. include stdint.h