Game Development Community

U8 / char consistancy.

by Stefan Lundmark · in Torque Game Engine · 12/31/2006 (5:47 am) · 4 replies

U8 / char consistancy:

Is there a specific reason that U8 is used in some places, but in other places it is not? I was under the impression that these typedefs were in place to ensure crossplatformability when types are of different size across platforms.

If this was true then I see no reason to use char at all. It also seems U8 is more forgiving than char when it comes to converting it to other types.

So what's the beef?

#1
12/31/2006 (7:18 am)
U8 == unsigned char
S8 == signed char
char == signed char

You should find that types such as char are only used as pointers in string manipulation functions (as with your typical C functions), whilst U8 is typically used for flags and lengths.
While these typedef's can be used to aid in solving cross-compiler / cross-platform portability issues (such as type size), they are also used to reduce typing. Just imagine having to type "unsigned int" instead of something simpler like "U32" every time.

p.s. its spelled "consistency", not "consistancy" :)
#2
12/31/2006 (7:32 am)
Well yeah, I knew what they stood for. (Basic Compiler Independent Types). I guess I just got tricked by the headline.

I always used the typedefs because they were shorter, so that makes sense. I just found myself wondering why they were mixed.

As for the correction on my spelling, I had no clue about that. Thanks James. :)
#3
01/01/2007 (4:21 am)
James is pretty-much-right.

We use U8 when we mean an 8-bit unsigned integer.

We use char when we want to use the local representation of a character.
#4
01/02/2007 (8:31 am)
Thanks to you both.

I was struggling with using U8 in string-like situations but just could not understand why anyone would use it when the string functions only accepted char. Now I understand, it is merely a way to swiftly see how many bits the datatype can hold.