Liste des Groupes | Revenir à cl c |
On 02/08/2024 11:48, Bart wrote:It also overflow in compile time in GoOn 02/08/2024 15:33, Kenny McCormack wrote:Also considerIn article <v8inds$2qpqh$1@dont-email.me>,>
Thiago Adams <thiago.adams@gmail.com> wrote:
...So it seams that anything is ok for unsigned but not for signed.>
Maybe because all computer gave same answer for unsigned but this is not
true for signed?
I think it is because it wants to (still) support representations other
than 2s complement. I think POSIX requires 2s complement, and I expect the
C standard to (eventually) follow suit.
>
C23 assumes 2s complement. However overflow on signed integers will still be considered UB: too many compilers depend on it.
>
But even if well-defined (eg. that UB was removed so that overflow just wraps as it does with unsigned), some here, whose initials may or may not be DB, consider such overflow Wrong and a bug in a program.
>
However they don't consider overflow of unsigned values wrong at all, simply because C allows that behaviour.
>
But I don't get it. If my calculation gives the wrong results because I've chosen a u32 type instead of u64, that's just as much a bug as using i32 instead of i64.
>
>
#include <stdio.h>
#include <limits.h>
int main()
{
//ULLONG_MAX*ULLONG_MAX/ULLONG_MAX/ULLONG_MAX is 1
printf("%ull", (ULLONG_MAX*ULLONG_MAX/ULLONG_MAX/ULLONG_MAX));
}
I am not Rust fan, but I prefer rust here. (compile time error)
https://godbolt.org/z/TP8WjThdE
in C it prints 0
https://godbolt.org/z/KWc8nhajc
Les messages affichés proviennent d'usenet.