My GNU-Linux platform (debian stretch) has the C types u_int8_t
, u_int16_t
, u_int32_t
and u_int64_t
defined in the file sys/types.h
while uint8_t
, uint16_t
, uint32_t
and uint64_t
are defined in stdint.h
. I have found these types useful in the course of practicing X86-64 assembly language and interacting with C. Is there any reason why I should prefer one header file over the other (be it 'best practice', portability etc.)?. Is the answer any different for C++?
Asked
Active
Viewed 1.1k times
8

Sven Williamson
- 1,094
- 1
- 10
- 19
-
1[This link](http://stackoverflow.com/a/5163960/6879826) to an answer for a related question suggests that these names [originated with BSD](http://lists.freedesktop.org/archives/release-wranglers/2004-August/000923.html). – ad absurdum Mar 23 '17 at 14:52
1 Answers
14
stdint.h
is standard C, which maps to cstdint
in standard C++.
sys/types.h
is not portable C.

Bathsheba
- 231,907
- 34
- 361
- 483
-
1
-
-
@ryyker [cstdint header](http://en.cppreference.com/w/cpp/header/cstdint). – François Andrieux Mar 23 '17 at 14:36
-
@JohnZwinck-- [`sys/types.h` is POSIX](http://pubs.opengroup.org/onlinepubs/009695399/basedefs/sys/types.h.html), but there are no `u_intN_t` types specified there. – ad absurdum Mar 23 '17 at 14:46
-
[Related](http://stackoverflow.com/questions/13642827/cstdint-vs-stdint-h). – PaperBirdMaster Mar 23 '17 at 14:52
-
Technically `int8_t` etc. are not required by compilers either. The `_least` ones are. They're likely to be there but they're not required by the C standard (I don't know about C++). – Pryftan Feb 14 '22 at 11:47