[Cryptography] Subject: Re: Swift and cryptography

Ben Laurie ben at links.org
Tue Jun 10 17:57:40 EDT 2014


On 10 June 2014 19:25, Arnold Reinhold <agr at me.com> wrote:
> // Initialize n to 255.
> int n = std::numeric_limits<uint8_t>::max();
>
>
> That is exactly the syntax bear was complaining about. Not very easy to
> remember

If you do C++, it is not rocket science. And if you don't, you
probably shouldn't.

> compared to:
>
> n = UInt8.max

There's always MAX_UINT8.

> Checks that are hard to implement are more likely to get left out.  And what
> happens if I define a new type whose underlying data is an int? And how do I
> write a generic function that checks for potential overflow? It seems
> straightforward the way Swift implements type properties. I'm not enough of
> an expert on C++ to say it can't be done, but I'd be curious to know how.

That's why C++ ends up like it does (and, btw, you could also write
SomeUInt8Thing.max() to get the same result.

Suppose I have a type T in hand, which is my int-of-unknown-size: in
C++ I can write

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


More information about the cryptography mailing list