Results 1 to 4 of 4
I guess I'm just a noob, but I notice that some C libraries (and even some C++ ones) tend to redefine the basic types with their own naming convention.
For ...
- 06-24-2010 #1Just Joined!
- Join Date
- May 2009
- Posts
- 8
Why redefine basic types in C?
I guess I'm just a noob, but I notice that some C libraries (and even some C++ ones) tend to redefine the basic types with their own naming convention.
For example, OpenGL redefines the basic types:
Is there some reason for this? Why use GLint instead of int?Code:from GL/gl.h typedef unsigned int GLenum; typedef unsigned char GLboolean; typedef unsigned int GLbitfield; typedef signed char GLbyte; typedef short GLshort; typedef int GLint; etc...
I've also seen some code that does this:
Is there some difference on windows between __int32 and int?Code:#ifdef _MSC_VER typedef unsigned __int32 u32; #else typedef unsigned int u32; #endif #ifdef _MSC_VER typedef __int32 s32; #else typedef signed int s32; #endif
Thanks again and excuse me for being a noob.
- 06-25-2010 #2
The reason is that OpenGL is supposed to be pretty portable. So, for example, a GLint should have the same size no matter what machine the code is compiled on.
How big, say, the datatype int is is determined by the vendor of the compiler. It may be 16bit on old computers, or 128bit somewhere in the future.
By having the datatypes wrapped, OpenGL code will be easier to port.
The same holds for:
If _MSC_VER is defined, the datatype __int32 is know by the compiler and chosen. If not, the compiler is believed to be old enough so that the "ordinary" int is of size 4 (byte) = 32bit.Code:#ifdef _MSC_VER typedef unsigned __int32 u32; #else typedef unsigned int u32; #endifDebian GNU/Linux -- You know you want it.
- 06-25-2010 #3Linux Newbie
- Join Date
- Mar 2010
- Posts
- 121
Yes, although it should be noted that the fixed sizes of int8_t, uint8_t, int16_t and so on from the stdint.h header, any other use of such types for the purposes of keeping code portable is redundant, since using the standard types is obviously more portable. They were useful before stdint.h was actually in the C standard, though.
- 06-27-2010 #4Just Joined!
- Join Date
- May 2009
- Posts
- 8
Did not know that. Thanks for that information!
Originally Posted by GNU-Fan
Thanks, thats good to know. From now on, I will use those.
Originally Posted by JohnGraham


Reply With Quote