> That's not a proper solution, if vec has more than SSIZE_MAX (but less than SIZE_MAX) elements.
this is impossible on any currently existing 64-bit CPUs. The CPUs with the biggest address space, some specific AArch64 and POWER10, just have 52 & 51 bits addressable. Every x86_64 CPU in existance is limited to 48 bits. By the time we reach 63 addressable bits, size_t will already be 128...
Announcement
Collapse
No announcement yet.
GCC 12 Adds Stack Variable Auto-Initialization, Other Security Improvements Forthcoming
Collapse
X
-
Originally posted by uxmkt View PostThat's not a proper solution, if vec has more than SSIZE_MAX (but less than SIZE_MAX) elements.
The only proper way is `if (vec.size() == 0) { /* just don't do this (and any subsequent code that would depends on any particular 'result' */ } else { result = vec.size() - 1; }`
Leave a comment:
-
Originally posted by pal666 View Postand proper solution [...] ssize(vec) - 1
The only proper way is `if (vec.size() == 0) { /* just don't do this (and any subsequent code that would depends on any particular 'result' */ } else { result = vec.size() - 1; }`
Leave a comment:
-
Originally posted by ddriver View PostWho in the right mind would want unsigned overflow protection?
Leave a comment:
-
Originally posted by carewolf View Post
People using unsigned integers for buffer lengths. But yeah I do wonder how that would work with all the other stuff unsigned ints needs to do that does require overflow acting as prescribed.
- Likes 1
Leave a comment:
-
Originally posted by bluescarni View PostI am just surprised that this option is not available.Last edited by pal666; 25 September 2021, 04:30 PM.
Leave a comment:
-
Originally posted by pal666 View Postyes, you are wrong. result wouldn't change if you replace 1 with 1u. compilers warn on mixed signedness comparison, but obviously only when it could matter(not when positive signed literal is promoted to unsigned)Last edited by bluescarni; 25 September 2021, 04:22 PM.
Leave a comment:
-
Originally posted by bluescarni View PostI am dismayed that I cannot make GCC or Clang emit a warning for this code. I was sure that any compiler would complain about mixed unsigned/signed arithmetic, but apparently I was wrong.
Leave a comment:
-
Originally posted by doom_Oo7 View Post
vec.size() - 1
Leave a comment:
-
antifeatures yay! instead of spending time trying to figure out how to hold everyones hand and make code slower, please stay focused on actual features like improving codegen.
if someone wants their hand held thats fine, they can use rust
Leave a comment:
Leave a comment: