code questions.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi GCC Help,

What is my confusion here? I am using gcc 4.1.2-14 on an i386 machine.
I don't know why I am getting a different value than I expect. Is
there a compiler flag I can use to make the expression evaluate
correctly according to my expectations? Thanks!

int main(char argc, char* agrv[]) {

	unsigned short a;
	unsigned short b;
	
	a = 0xFFFF;
	b = 0x3FC;

	a = (a + 1) % b;
	printf ("A is 0x%x\n", a);
	// I expect the answer to be 0 and it is not! It is 0x100. Why is this?

	a = 0xFFFF;

	a = (a + 1);
	printf ("A is 0x%x\n", a);
	// I expect the answer to be 0 and it is.

	a = a % b;
	printf ("A is 0x%x\n", a);
	// I expect the answer to be 0 and it is.

}

Best Regards,

Scott

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux