Re:Bounded Integer: Header-only C++ library replaces integer...
by HelloNurse on Sunday September 29, 2019 @12:03PM
(#21107792)
On a different platform, these "friendly" types can be larger, typically 2 or 4 times larger which can be devastating for performance, or smaller, leading to overflow. They are only "usable" if you restrict yourself on one version, of one compiler, on one hardware platform.
[ Parent
| on HN ]
Re:Bounded Integer: Header-only C++ library replaces integer...
by Fronzie on Sunday September 29, 2019 @01:05PM
(#21108199)
Since C++11 there are types like 'uint_fast32_t', which does allow for platform independent code.
Re:Bounded Integer: Header-only C++ library replaces integer...
by vips7L on Sunday September 29, 2019 @12:18PM
(#21107889)
Does C++ not have int32_t and the like from C?
Re:Bounded Integer: Header-only C++ library replaces integer...
by nitwit005 on Sunday September 29, 2019 @12:22PM
(#21107911)
It does. I personally stick to those exclusively except for for loop index variables.
Re:Bounded Integer: Header-only C++ library replaces integer...
by vips7L on Sunday September 29, 2019 @12:45PM
(#21108063)
What would be different about loop variables? I don't really write C++.
Re:Bounded Integer: Header-only C++ library replaces integer...
by rleigh on Sunday September 29, 2019 @01:39PM
(#21108408)
I'm assuming here that they would use the `size_type` for the container they are iterating over. Otherwise I'm not sure.
Re:Bounded Integer: Header-only C++ library replaces integer...
by ncmncm on Sunday September 29, 2019 @03:27PM
(#21109132)
An unsigned type is sometimes a poor choice for a loop index. The compiler then cannot assume the loop will terminate, and generate worse code. Usually this doesn't matter -- until you discover it did.
Re:Bounded Integer: Header-only C++ library replaces integer...
by rleigh on Sunday September 29, 2019 @03:42PM
(#21109231)
Good point. Probably not a problem in practice for most containers, but yet another reason for why the STL (and C library, for that matter) should have used a signed size type from the beginning.
Re:Bounded Integer: Header-only C++ library replaces integer...
by nitwit005 on Sunday September 29, 2019 @06:10PM
(#21109928)
Yep, it's to match vector/array size_type and difference_type, although I tend to just use size_t and ptrdiff_t directly.
Re:Bounded Integer: Header-only C++ library replaces integer...
by glouwbug on Sunday September 29, 2019 @12:27PM
(#21107945)
It's a good choice. Sometimes your best choice for a general purpose int is
typedef Int int32_t;
for the entire compilation as a whole, and when things get screwy just bump Int up to int64_t and take the performance hit for the extra bit of safety
Re:Bounded Integer: Header-only C++ library replaces integer...
by ncmncm on Sunday September 29, 2019 @03:27PM
(#21109140)
"i32" is better.