problems with mod

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Ice_364

problems with mod

Post 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
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:problems with mod

Post 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 ...
Tim

Re:problems with mod

Post 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.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:problems with mod

Post 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 ...
IcE_364

Re:problems with mod

Post 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.
Post Reply