[Cryptography] GCC bug 30475

Nemo nemo at self-evident.org
Sun Apr 27 00:44:02 EDT 2014


Jerry Leichter <leichter at lrw.com> writes:

> The actual representation of types has been pinned down somewhat more
> tightly than in the past.

C99 introduced the "pinning down" to twos-complement, ones-complement,
and sign-magnitude representations (plus padding bits).

No C++ standard ever adopted any similar language, by the way, leading
to some truly obscure possibilities:

    http://stackoverflow.com/questions/13150449/

> It's easy to determine the maximum value of an *unsigned* type.

Indeed:

    UnsignedType n = -1;

...is guaranteed to work, for every unsigned integral type, by every C
and C++ standard ever.

> It's not clear to me now that there is any portable way to determine
> the maximum value of a *signed* type.

C has <limits.h> which is mandated to provide SHORT_MAX, INT_MAX,
LONG_MAX, etc. This does not help if it's an unknown typedef, but it is
portable.

The C++ standards all specify <limits> which provides the
std::numeric_limits type traits, allowing:

    MySignedType n = std::numeric_limits<MySignedType>::max();

Computations based on types are usually easier in C++. Whether that is a
strength or a weakness depends on your point of view.

 - Nemo
   https://self-evident.org/


More information about the cryptography mailing list