u32 vs int f32 vs float

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
ulao
Posts: 274
Joined: Fri Mar 28, 2008 2:13 am

u32 vs int f32 vs float

Post by ulao »

I'm not sure when i should use an int or when I should use a u32. I'm guessing u32 is Irrlicht's int, I could be wrong. If I use a value time I must make it an u32 for getTime() to work. but If I use abs from math.h I need to use a int. abs( int value );.. If I use a u32 it complains. I guess I coudl cast it? So I'm just wondering what is suggested here?
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

u32 is a typedef for an unsigned 32-bit integer, on most platforms this is "unsigned int". s32 is a signed 32-bit integer, or "int"
s16 and u16 are shorts, c8 and u8 are char. f32 is a float and f64 is a double.
You can't use abs with an unsigned value because it can never be negative
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
ulao
Posts: 274
Joined: Fri Mar 28, 2008 2:13 am

Post by ulao »

thx bitplane, is there an advantage using s32 vs int? I'm sure there is a perfectly good reason Irrlicht does this, I'm just not sure what it is.
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

It's for portability. You can safely assume that a u32 is an unsigned 32 bit integer and can hold over 4 billion values; sizeof(u32) is always 4. The only thing you can assume about an int is that it is at least 16 bits, so it might be any size depending on the processor and compiler.
So when you port Irrlicht to run on your calculator, you just need to typedef the correct types in irrTypes.h and everything will work without problems... in theory. (why not try it? :D)
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

bitplane wrote:The only thing you can assume about an int is that it is at least 16 bits
It is actually perfectly legal for an int to be just one byte, provided that the size of a short is no more than one byte.

Travis
ulao
Posts: 274
Joined: Fri Mar 28, 2008 2:13 am

Post by ulao »

bitplane wrote:It's for portability. You can safely assume that a u32 is an unsigned 32 bit integer and can hold over 4 billion values; sizeof(u32) is always 4. The only thing you can assume about an int is that it is at least 16 bits, so it might be any size depending on the processor and compiler.
So when you port Irrlicht to run on your calculator, you just need to typedef the correct types in irrTypes.h and everything will work without problems... in theory. (why not try it? :D)
ahhhh, cool. Ok got it!!
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

vitek wrote:
bitplane wrote:The only thing you can assume about an int is that it is at least 16 bits
It is actually perfectly legal for an int to be just one byte, provided that the size of a short is no more than one byte.
I read somewhere that INT_MIN had to be <= -32767, which would mean ints must be at least 16-bit. I haven't got my C++ reference book handy at the moment, but I found this on Google books.. Is that wrong?
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

You are absolutely right. 5.2.4.2.1 Sizes of integer types in the C99 standard does say that INT_MIN <= -32767 and INT_MAX >= 32767, which would require it to be 16-bit.

Apparently I was remembering that a int could be no smaller than a short and applying that all the way up the heirarchy. Sorry about that.
Post Reply