irrTypes.h not standard compilant.

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
dejai
Posts: 522
Joined: Sat Apr 21, 2007 9:00 am

irrTypes.h not standard compilant.

Post by dejai »

The current irrTypes.h defines s32 to be the following: typedef signed int s32; (on non windows systems) It is totally valid for a signed int to be 16 bits. In fact its range is specified in minimum range: signed int: -32767 to 32767 which is the same as a signed short. Generally this is not the case, however on certain embedded systems you cannot guarantee this. I propose the following solution. typedef int32_t s32; with a #include <cstdint>. However since Visual Studios compiler only added this C99 feature in 2010, keep the microsoft specific boiler plate. Now I think about it perhaps being standard compliant would be less portable then not standard compilant in which case you could do the following.

Code: Select all

 
#ifdef (LONG_MAX == INT32_MAX)
typedef signed long s32;
#endif
#elif (INT_MAX == INT32_MAX)
typedef signed int s32;
#endif
#elif (SHORT_MAX == INT32_MAX)
typedef signed short s32;
#endif
#else
#error "Platform does not support 32 bit integers"
#endif
 
This last solution would be portable (assuming you had definitions for INT32_MAX available) it would be standard compilant and not add runtime cost, with almost no compiler overhead. Just a thought opinions are welcome.
Programming Blog: http://www.uberwolf.com
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: irrTypes.h not standard compilant.

Post by hybrid »

We would need a configure script for this, otherwise it is problematic to check for existence of these additional includes. So yes, we could opt-in to add an include and a typedef based on the cstdint, but only if it is properly embraced by compile guards which are set elsewhere in system headers. Otherwise we have to add additional typedefs for those platforms using just 16bit integers (although I doubt that you will find any graphics capable system which is not 32bit). This is just reactive, but it avoids trouble with all those standard platforms out there.
Post Reply