Odd modulus problem w/GCC 4.1.2

Programming, for all ages and all languages.
Post Reply
User avatar
inx
Member
Member
Posts: 142
Joined: Wed Mar 05, 2008 12:52 am

Odd modulus problem w/GCC 4.1.2

Post by inx »

I'm most likely missing something very basic, but I'm having a big problem using the % operator in GCC 4.1.2. The form of modulus that's manifesting itself in my setup retains some functionality, but is only mildly useful. It's kind of just behaving like a boolean "Is there a remainder?" function. It just seems to spit out 0 if there is no remainder, and the second operand if there is one. I.E. 42 % 24 = 0, but 30 % 12 = 12. Anyone have any insight?
User avatar
01000101
Member
Member
Posts: 1599
Joined: Fri Jun 22, 2007 12:47 pm
Contact:

Post by 01000101 »

well 30 % 12 should be 6... hmm, reinstall?

or maybe there is a different logic, 6*2 = 12, and that is the value given earlier. are you sure it is always the second value being returned?

either way, its a reinstallable issue.
jzgriffin
Member
Member
Posts: 190
Joined: Tue Sep 26, 2006 1:40 pm
Libera.chat IRC: Nokurn
Location: Ontario, CA, USA
Contact:

Post by jzgriffin »

I agree with 01000101. Try reinstalling. By the way, what distribution of GCC are you using? MinGW, DJGPP, a pre-compiled Linux package, or a source installation. If it's source, post your configure flags.
User avatar
inx
Member
Member
Posts: 142
Joined: Wed Mar 05, 2008 12:52 am

Post by inx »

The 30 % 12 was kind of pulled out of thin air (although I did test that number for the sake of due diligence before posting lol). I first noticed it when some padding code wasn't working correctly, so it was more on the order of x % PAGE_SIZE, and always getting PAGE_SIZE if there was a remainder. I've been working around it since then, since I save cycles not caring what the remainder is on that, anyway. However, I'm trying to go back through my code now that I've gotten somewhat far along and replace some rudimentary linear lookups with hash tables, so I kind of need it now.

It's the prebuilt package from Debian 4.0r0. The problem doesn't occur in programs compiled normally (e.g. gcc -o foo foo.c) w/glibc et. al. It only occurs in my kernel code. My pertinent compilation parameters are '-Wall -Werror -nostartfiles -no-stdlib -no-stdinc -fno-builtin', if that helps.
User avatar
Wave
Member
Member
Posts: 50
Joined: Sun Jan 20, 2008 5:51 am

Post by Wave »

Compile with -S and post the resulting .s file here so we can have a look at it together with the c source (try to reproduce it in a small file).
Conway's Law: If you have four groups working on a compiler, you'll get a 4-pass compiler.
Melvin Conway
Post Reply