Yes. *Another* problem is the lack of operations on size_t (and
unsigned types in general) that behave in a manner other than the one
chosen by the standard. This inflexibility of the language makes some
useful operations difficult to implement, and in some cases impossible
to implement both portably and efficiently.
On the other hand, "fixing" this "problem" would make the language
more complicated, and it's not entirely sure that it would be worth
it.
so is it not possible to save "capra e cavoli"?
in a pc with 32bits cpu
where is the problem in have 31bits unsigned size_t (all like say the
C standard) and to have the 32th bit that say if there is some
"overflow" (or use mod) in the middle of some computation?
in a pc with 64bits cpu
where is the problem in have 63bits unsigned size_t (all like say the
C standard) and to have the 64th bit that say if there is some
"overflow" (or use mod) in the middle of some computation?
if a function want to see if that some size_t variable has overflow
see the last bit in that variable
than could be added another type that use (-1) for error
and not have "mod" behaviour like below, for computation
that can not overflow in mod
---------------------
/* it could do size_t multiplication
for numbers [0..2^32-2]
*/
asm{
multix:
push edx
mov eax, [esp+ 8]
cmp [esp+12], -1
je .1
cmp eax, -1
je .f
xor edx, edx
mul dword[esp+12]
cmp edx, 0
je .f
.1:
mov eax, -1
.f:
pop edx
ret 8
}
asm{
addsize:
mov eax, [esp+ 4]
cmp [esp+8], -1
je .1
cmp eax, -1
je .f
add eax, [esp+8]
jnc .f
.1:
mov eax, -1
.f:
pop edx
ret 8
}
asm{
subsize:
mov eax, [esp+ 4]
cmp [esp+8], -1
je .1
cmp eax, -1
je .f
sub eax, [esp+8]
j>= .f
.1:
mov eax, -1
.f:
pop edx
ret 8
}
unsigned _stdcall multix(unsigned a, unsigned b);
uns32 operator*(uns32 x, uns32 y) {return multix(x, y);}
unsigned _stdcall addsize(unsigned a, unsigned b);
uns32 operator+(uns32 x, uns32 y) {return addsize(x, y);}
unsigned _stdcall subsize(unsigned a, unsigned b);
uns32 operator-(uns32 x, uns32 y) {return subsize(x, y);}
etc
uns32 result, a, b, c, d, h;
.....
result=a*b+c*d-h;
i forget to say if there is some overflow in some place
if(result==-1) error;
the same like above for an signed int type