On 14.09.2018 21:45, Paul wrote:
> Could someone possibly explain to me the relationship between
> fixed width integer types and the std namespace?
>
> On my compiler, if I #include <cstdint> then
> std::int8_t yy = 65; works fine but also
> int8_t z = 65; also works.
>
> (And yes, it gives 'A').
> Does int8_t belong to the std namespace or not?
It Came From Outer Space.
Or, well, C99.
> How can this designation be optional?
<cstdint> guarantees to provide it in namespace `std`, and may also
provide it in the global namespace.
<stdint.h> guarantees to provide in the global namespace, and may also
provide it in the `std` namespace.
A header wrapper such as ¹<stdlib/c/stdint.hpp> that includes both
headers, guarantees that the name is in both the global namespace and
the `std` namespace. Guaranteed behavior is IMHO preferable. But if you
don't want to use such a wrapper, then including <stdint.h> is the more
practical choice: <cstdint> just adds complication, for historical
idealistic (or what I believe to be idealistic) reasons, and effectively
reduces portability, since non-qualified use of the name may compile
with the compiler used for original development, and not with others.
Cheers & hth.,
- Alf
Notes:
¹ <url:
https://github.com/alf-p-steinbach/Wrapped-stdlib/tree/master/source/c>