Page 1 of 1

problems with mod

Posted: Sun Oct 12, 2003 9:49 am
by Ice_364
Hi :)

When i do the following:

if((_tick % 100) == 0) {
/* nothing here */
}

it compiles. but when i put something like i++; in the if then the compiler complains about

undefined reference to `__umoddi3'

Thanks

Re:problems with mod

Posted: Sun Oct 12, 2003 3:20 pm
by Pype.Clicker
this suggest your '_ticks' is too large (long long, or something alike) for what your compiler natively supports. The compiler then generate a call to a library in order to implement the '%100', but you have no such library with you ...

Re:problems with mod

Posted: Sun Oct 12, 2003 4:17 pm
by Tim
If you're sure you want to use 64-bit integers (i.e. you know you haven't made a mistake), link against libgcc.a to allow the use of 64-bit division and modulus. libgcc gives you the alloca function, too.

Re:problems with mod

Posted: Mon Oct 13, 2003 1:24 am
by Pype.Clicker
you could still wonder "why the **** does it fail only when i have _ticks++ ?" . I'm not 100% sure of my response as i don't have the whole code, but i guess this is due to the fact that without _ticks++, the _ticks variable appears as a constant for the compiler, thus it doesn't have to worry about generating code that performs the modulo: it just computes the final value and maybe even replace the "if" block by either ever-executed or never-executed block ...

Re:problems with mod

Posted: Tue Oct 14, 2003 2:42 am
by IcE_364
I think the compiler just removes the entire if statement if there's nothing to do in the if.

I will try linking with libgcc tonight.