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

Not an xwpe question.



I am having a problem with, I think, my compiler and I just wanted to know if
anyone eles is having a similar problem. I am using egcs 2.91.66 on Red Hat 6.1.
My problme is unsigned ints and unsigned longs, they are singend. I have been
having problems with my software and wrote this code to find that problem.


#include <stdio.h>

void main(void)
{
	unsigned long int MyULong;
	unsigned char MyUChar;
	unsigned int MyUInt;
	unsigned short MyUShort;
	double	MyDouble;

	printf("sizeof(char)=%d\n",sizeof(char));    		// Shows 1, good
	printf("sizeof(int)=%d\n",sizeof(int));				// Shows 4, good
	printf("sizeof(long)=%d\n",sizeof(long));				
// Shows 4, not great. A long should be bigger then and int, but it is ok


	printf("sizeof(MyUChar)=%d\n",sizeof(MyUChar));		// Shows 1, good
	MyUChar=0;
	MyUChar--;
	printf("MyUChar=%d\n\n",MyUChar);						// Show 255, good

	printf("sizeof(MyUInt)=%d\n",sizeof(MyUInt));		// Shows 4, good
	MyUInt=0;
	MyUInt--;
	printf("MyUInt=%d\n\n",MyUInt);							// Shows -1, wrong!
	// An unsigned int of 4 bytes should be (2^32)-1 = 4294967295 not -1

	printf("sizeof(MyUShort)=%d\n",sizeof(MyUShort));	// Shows 2, good
	MyUShort=0;
	MyUShort--;
	printf("MyUShort=%d\n\n",MyUShort);						// Shows 65535, good

	printf("sizeof(MyULong)=%d\n",sizeof(MyULong));		// Shows 4, good
	MyULong=0;
	MyULong--;
	printf("MyULong=%d\n\n",MyULong);						// Shows -1, wrong!

	printf("sizeof(MyDouble)=%d\n",sizeof(MyDouble));	// Shows 8, good
	MyDouble=0;
	MyDouble--;
	printf("MyDouble=%d\n\n",MyDouble);						// Shows 0, not what I was expecting, but fine.

	// I need a 32 bit unsigned type. Am I missing it? Is my compiler working ok?
	// Sould I send an e-mail to the egcs people?
	// Is there a GNU help file that can be included with the Xwpe IDE? Man pages don't cut it.
}



 -- 

Roy Souther roy@silicontao.com
Take back control of your computer!
www.silicontao.com