Click to See Complete Forum and Search --> : SDL Unit8


acid45
06-08-2005, 12:32 PM
Does an SDL Unit8 mean any unsigned numeric value from 0 to 255?

Thus SDL Unit32 would mean any unsigned numeric value from 0 to 16,777,215?

Maybe integers. It's probably some sort of struct defined on the site just not easy to find.

In code samples they highlight it similarly to other variable types. So I'm GUESSING it's a structure.

I tried reading the Introduction, I couldn't find it there. I'm going through the WIKI pages and I can't find it there. Google turned up...well try searching for SDL Unit8. Searching for just Unit 8 or What is Unit8 doesn't turn up any better results. The FAQs are...well FAQs.

Using site search reveals that it points to a byte. Which makes me think the value of a Unit8 probably looks something like 0x00 and Unit32 looks like 0x00000000 where the leading 0x is hex identifiers and the rest are...or something like that. If it does I'm gona have to go learn a little more about HEX.

Yay for n00b questions.

bwkaz
06-08-2005, 06:39 PM
Uhh... your searching problem might be that you're using the wrong term. ;)

It's a Uint8, not a Unit8. (Note the n and i characters.) :)

Uint8 is guaranteed to be an unsigned integer, 8 bits wide. It's a typedef, not a struct (the real type could depend on the architecture).

Uint32 is guaranteed to be an unsigned integer, 32 bits wide. It is also a typedef. The real type definitely does depend on the architecture.

The only guarantees that you get from C (regarding integers at least) are that short int is at least 16 bits, int is at least 16 bits, and long int is at least 32 bits. There is no defined size to any of these types -- any of them can be longer. It is true that on Intel, on Linux, an int is 32 bits, but on some 64-bit systems, an int is 64 bits.

UintXXX is always exactly XXX bits in size.

The range on a Uint8 is 0 to 255 (255 is the largest number that can be represented in 8 bits). The range on a Uint32 is 0 to 4294967295 (4294967295 is the largest number that can be represented in 32 bits).

On Linux, this is 0 to UCHAR_MAX and 0 to UINT_MAX (the constants come from limits.h), but that's not true everywhere. UCHAR_MAX is the largest value that can fit into an unsigned char, and UINT_MAX is the largest value that can fit into an unsigned int. Some architectures make UINT_MAX be 65535 (those that have 16-bit ints), and some make UINT_MAX be some enormous number (2 to the 64th minus 1 -- these are the architectures where ints are 64 bits).