News for hackers. Stuff that matters.
Re:A Special Kind of Hell: intmax_t in C and C++ by josefx on Saturday December 05, 2020 @05:01PM (#25318838)
> at least not in code that is intended to be remotely portable across time, space and architecture.

intmax_t exists probably because most integer types in C are not portable. You can't write C code that uses int64_t and expect it to compile, the type doesn't have to exist, neither do int32_t or int16_t. Say you have a generic int lowestBitSet(intmax_t) function and want to make it available, you don't care how large the input integer is as long as you do not truncate the largest type available to whoever ends up using it. Without intmax_t you end up with library developers having to either setting their own upper limit, limiting the portability of their library or checking for the availability of each type themselves.

Re:A Special Kind of Hell: intmax_t in C and C++ by PaulDavisThe1st on Saturday December 05, 2020 @05:52PM (#25319205)
I don't use int64_t and expect it to exist. I use int64_t and expect compilation to fail if stdint.h doesn't define it. It would be a problem, but much less of a problem than using intWhatever_t, having compilation work, but having no idea what the bounds were.

intmax_t doesn't define an upper limit either, as TFA explains, because you don't know at runtime what the limit really is.

Re:A Special Kind of Hell: intmax_t in C and C++ by josefx on Sunday December 06, 2020 @04:00AM (#25322174)
> but having no idea what the bounds were.

The idea for the library writer are that the bounds are large enough for whatever the user needs. User inputs a int64_t? Great the type intmax_t on that system is at least int64_t wide by definition. System doesn't have a int64_t ? Great the user can at best use a int32_t, which intmax_t would once again support.

> intmax_t doesn't define an upper limit either, as TFA explains

Yeah, it would almost be sad that C++ is getting bitten by Cs lack of name mangling. Almost because it is kinda pointless to define a maximum integer in a language where any programmer can add their own fixed sized integer types, so a generic library supporting arbitrary sized integers would have to take template parameters anyway.

Re:A Special Kind of Hell: intmax_t in C and C++ by young_unixer on Sunday December 06, 2020 @12:28AM (#25321318)
The standard requires longs to be at least 32 bits wide. Then how can int32_t not exist?

And C99 requires long longs to be at least 64 bits wide.

Re:A Special Kind of Hell: intmax_t in C and C++ by josefx on Sunday December 06, 2020 @04:11AM (#25322226)
While that isn't really relevant as the sizes used by my example could just be larger (if intmax_t worked as intended, which of course it doesn't), the fixed width types are all optional. For example on systems that use ones complement you would have a intmax_t, but no int32_t or any of the others.
Re:A Special Kind of Hell: intmax_t in C and C++ by pjmlp on Sunday December 06, 2020 @01:58AM (#25321710)
When targeting an 8 or 16 bit processor.