Bitfield subtlety

Niels Möller nisse at lysator.liu.se
Wed Mar 28 05:08:54 UTC 2018


tg at gmplib.org (Torbjörn Granlund) writes:

> In C++, a bit field whose base type is not explicitly signed or unsigned
> gets undefined signedness.  It would be desirable to use stdint.h's
> int64_t, but while that is signed, it is not guaranteed to be explicitly
> so.

Ouch, it's pretty subtle (and unfriendly) if "long" and "signed long"
don't quite mean the same thing. And remedying by writing something like
"signed int64_t" isn't valid either?

> I see no nice solution to the C++ rule.  I suppose that if we decide to
> go with bit fields here, we will simply not support problematic C++
> compilers.  Or we arm autoconf to probe for this too, and stay away from
> stdint.h.

Or stick to a single uint64_t and shift and mask operations to access
the fields.

Regards,
/Niels

-- 
Niels Möller. PGP-encrypted email is preferred. Keyid 368C6677.
Internet email is subject to wholesale government surveillance.


More information about the gmp-devel mailing list