Hello,

TLDR: C++ offers signed and unsigned integer types, e.g. `int32_t` and 
`uint32_t`. Should variables which *should* not contain negative values 
have a signed or unsigned type? Arguments for both types can be found in 
Bjarne Stroustrup's paper [1].

I've discussed the issue in recent days with Botond, Emilio and Masayuki, 
since we disagreed on the answer and Mozilla's style guide [2] doesn't 
explicitly answer it either. The latter is based on Google's C++ Style 
Guide, which recommends using signed types [3].

For the sake of completeness, the most recent discussion about this on 
dev.platform can be found at [4].

Botond's proposal was to "contain" the use of unsigned types to certain 
layers of the code and cast when entering or exiting those layers [5] and 
to follow Google's Style Guide [2] for new code.
While I think that makes sense, I'd of course accept other decisions as 
well.
The important issue is to come to *some* decision which should be added to 
Mozilla's style guide. Otherwise, such discussions will emerge again, 
unnecessarily delaying reviews.

I don't know, how much static analysis currently helps to detect overflows 
of signed types, which would be one benefit of using signed instead of 
unsigned types. Does anyone know?

What do other people think about this?

Mirko

[1] http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1428r0.pdf.
[2] 
https://firefox-source-docs.mozilla.org/code-quality/coding-style/coding_style_cpp.html#c-c-practices
[3] https://google.github.io/styleguide/cppguide.html#Integer_Types
[4] 
https://groups.google.com/g/mozilla.dev.platform/c/ekmfMjjF7Mg/m/ir6HXSYbAwAJ
[5]

-- 
You received this message because you are subscribed to the Google Groups 
"[email protected]" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/a/mozilla.org/d/msgid/dev-platform/c5e54c66-2fdb-4174-8093-0bbf2c62b102n%40mozilla.org.

Reply via email to