Just add some "const" and
All ok this doing what I thought
even if I not find where I
wrote that...
Thank you
friend ou32* val(void)
{u32 r=ic; ++ic; if(ic>=63) ic=0; R maa+r;}
friend u32 ErrVal(void){R -1;} // value for error
ou32() {v=0;}
ou32(u32 a){v=a;}
ou32(i32 a){v=(u32)(a<0? -1: a);}
ou32(u8 a){v=a;}
ou32(i8 a){v=(u32)(a<0? -1: a);}
ou32(u16 a){v=a;}
ou32(i16 a){v=(u32)(a<0? -1: a);}
ou32(const ou32& a){v=a.v;}
ou32& operator=(const ou32& a){v=a.v; R *this;}
ou32& operator=(u32 a){v=a; R *this;}
ou32& operator=(i32 a){v=(u32)(a<0? -1: a); R *this;}
ou32& operator=(u16 a){v=a; R *this;}
ou32& operator=(i16 a){v=(u32)(a<0? -1: a); R *this;}
ou32& operator=(u8 a){v=a; R *this;}
ou32& operator=(i8 a){v=(u32)(a<0? -1: a); R *this;}
ou32& operator*=(const ou32& a){v=u32omul(v, a.v); R *this;}
ou32& operator+=(const ou32& a){v=u32oadd(v, a.v); R *this;}
ou32& operator-=(const ou32& a){v=u32osub(v, a.v); R *this;}
ou32& operator/=(const ou32& a){if(v==-1||a.v==-1||a.v==0) v=-1;
else v=v/a.v;
R *this;
}
ou32& operator++(){v=(v==-1? -1: ++v); R *this;}
ou32& operator++(int)
{ou32 *t; t=val(); *t=*this; if(v!=-1) ++v; R *t;}
ou32& operator--(){v=(v==-1? -1: --v); R *this;}
ou32& operator--(int)
{ou32 *t; t=val(); *t=*this; if(v!=-1) --v; R *t;}
friend ou32& operator*(const ou32& a, const ou32& b)
{ou32 *r; r=val(); r->v=u32omul(a.v, b.v); R *r;}
friend ou32& operator+(const ou32& a, const ou32& b)
{ou32 *r; r=val(); r->v=u32oadd(a.v, b.v); R *r;}
friend ou32& operator-(const ou32& a, const ou32& b)
{ou32 *r; r=val(); r->v=u32osub(a.v, b.v); R *r;}
friend ou32& operator/(const ou32& a, const ou32& b)
{ou32 *r;
r=val();
if(a.v==-1||b.v==-1||b.v==0) r->v=-1;
else r->v=a.v/b.v;
R *r;
}
friend ostream& operator<<(ostream& ostr, ou32& a)
{if( a.v==-1 ) ostr<<"ErrElm"; else ostr<<a.v; R ostr;}
friend i32 operator==(const ou32& a, const ou32& b){R a.v==b.v;}
friend i32 operator!=(const ou32& a, const ou32& b){R a.v==b.v;}
friend i32 operator<=(const ou32& a, const ou32& b){R a.v<=b.v;}
friend i32 operator>=(const ou32& a, const ou32& b){R a.v>=b.v;}
friend i32 operator<( const ou32& a, const ou32& b){R a.v< b.v;}
friend i32 operator>( const ou32& a, const ou32& b){R a.v> b.v;}
u32 v;
static u32 ic;
static ou32 *maa;
};
u32 ou32::ic=0;
ou32 ma[64];
ou32* ou32::maa=ma;
void fo(void)
{u32 i, j, k;
ou32 ui, uj, uk;
// ou32
ui.v=ErrVal(); // ui.v=-1
--ui.v;
uj=ui+3u; // overflow +
if(uj.v!=-1) P("ou32 error +\n");
ui=3u;
uj=ui-(ou32)7u; // overflow -
if(uj.v!=-1) P("ou32 error -\n");
ui=0xFFFFF;
uj=ui*(u32)0xFFFF; // overflow *
if(uj.v!=-1) P("ou32 error *\n");
ui=0xFFFFF;
uj=ui/(u32)0; // overflow /
if(uj.v!=-1) P("ou32 error / \n");
P("If no print but only this: all ok\n");
}
int main(void)
{if( sizeof(u32)!=4 || sizeof(u16)!=2 )
{P("Basic type error\n"); R 0;}
fo();
R 0;
}
/*
; ui.v=ErrVal(); // ui.v=-1
;
mov dword ptr [ebp-4],-1
;
; --ui.v;
;
dec dword ptr [ebp-4]
;
; uj=ui+3u; // overflow +
;
mov dword ptr [ebp-16],3
mov eax,dword ptr [ebx]
inc dword ptr [ebx]
cmp dword ptr [ebx],63
jb short @2
xor edx,edx
mov dword ptr [ebx],edx
#sembra che converte 3u in ou32 utilizzando l'array tramite val()
#inline [**come dovrebbe essere**]
# ma io non ho fatto la conversione u32 a ou32 tramite val()
#tutto automatico?
@2:
@3:
mov esi,eax
shl esi,2
add esi,dword ptr [@@ou32@maa]
push dword ptr [ebp-16]
push dword ptr [ebp-4]
call @u32oadd
mov dword ptr [esi],eax
mov eax,esi
mov edx,dword ptr [eax]
mov dword ptr [edi],edx
#chiama l'operatore + (ou32 ou32) anche esso inline... ok sembra
;
; if(uj.v!=-1) P("ou32 error +\n");
;
cmp dword ptr [edi],-1
je short @4
push offset s@
call @_printf
pop ecx
;
;
; ui=3u;
;
@4:
mov dword ptr [ebp-4],3
;
; uj=ui-(ou32)7u; // overflow -
;
mov dword ptr [ebp-20],7
mov eax,dword ptr [ebx]
inc dword ptr [ebx]
cmp dword ptr [ebx],63
jb short @5
xor ecx,ecx
mov dword ptr [ebx],ecx
@5:
@6:
mov esi,eax
shl esi,2
add esi,dword ptr [@@ou32@maa]
push dword ptr [ebp-20]
push dword ptr [ebp-4]
call @u32osub
mov dword ptr [esi],eax
mov eax,esi
mov edx,dword ptr [eax]
mov dword ptr [edi],edx
;
; if(uj.v!=-1) P("ou32 error -\n");
;
cmp dword ptr [edi],-1
je short @7
push offset s@+14
call @_printf
pop ecx
;
;
;
; ui=0xFFFFF;
;
@7:
mov dword ptr [ebp-4],1048575
;
; uj=ui*(u32)0xFFFF; // overflow *
;
mov dword ptr [ebp-24],65535
mov eax,dword ptr [ebx]
inc dword ptr [ebx]
cmp dword ptr [ebx],63
jb short @8
xor ecx,ecx
mov dword ptr [ebx],ecx
@8:
@9:
mov esi,eax
shl esi,2
add esi,dword ptr [@@ou32@maa]
push dword ptr [ebp-24]
push dword ptr [ebp-4]
call @u32omul
mov dword ptr [esi],eax
mov eax,esi
mov edx,dword ptr [eax]
mov dword ptr [edi],edx
;
; if(uj.v!=-1) P("ou32 error *\n");
;
cmp dword ptr [edi],-1
je short @10
push offset s@+28
call @_printf
pop ecx
;
;
; ui=0xFFFFF;
;
@10:
mov dword ptr [ebp-4],1048575
;
; uj=ui/(u32)0; // overflow /
;
xor ecx,ecx
mov dword ptr [ebp-28],ecx
mov eax,dword ptr [ebx]
inc dword ptr [ebx]
cmp dword ptr [ebx],63
jb short @11
xor edx,edx
mov dword ptr [ebx],edx
@11:
@12:
mov ecx,eax
shl ecx,2
add ecx,dword ptr [@@ou32@maa]
cmp dword ptr [ebp-4],-1
je short @15
cmp dword ptr [ebp-28],-1
je short @15
cmp dword ptr [ebp-28],0
jne short @13
@15:
mov dword ptr [ecx],-1
jmp short @14
@13:
mov eax,dword ptr [ebp-4]
xor edx,edx
div dword ptr [ebp-28]
mov dword ptr [ecx],eax
@14:
mov eax,ecx
mov ecx,dword ptr [eax]
mov dword ptr [edi],ecx
;
; if(uj.v!=-1) P("ou32 error / \n");
;
?live16387@224: ; EDI = &uj
cmp dword ptr [edi],-1
je short @16
push offset s@+42
call @_printf
pop ecx
;
;
; P("If no print but only this: all ok\n");
;
?live16387@240: ;
@16:
push offset s@+57
call @_printf
pop ecx
;
;
; }
;
*/