• entries
101
122
• views
58047

# #gamedev

252 views

Some things baffle me.

This is an excerpt from #gamedev of a roughly 200 line code dump to the paste site of what appeared to be a MD3 loader.
if(!skinfile){        printf("sdfsdf");        cout<<"\nUnable to access skin file";}

Here is another line from the code.
unsigned int temptexture=-1;

Normally I want to help newbies out - but maybe some people just aren't cut out for programming.

The second one is a declaration of a GLuint which is used in OpenGL for textures. Granted, he should be using a typedef

typedef GLuint GLtexture;

or something to make the code sane. I'm not sure why he's setting it to -1 though; its an unsigned int for a reason. He should default initialize it to 0, the OpenGL "null texture". As for the first one... wtf? sdfsdf.

Quote:
 Original post by Mushu As for the first one... wtf? sdfsdf.

"sdfsdf" is pretty bad - but the use of both printf() and cout within 2 lines of code seems a bit curious

I don't mean to come across as smug and making fun of a noob - but sometimes I have to wonder wtf?

Lol!

I've never tried assigning a negative value to an unassigned int?

Say it was 3 bits signed and 4 bits unsigned...

-1 = 1110 (I think) signed
-1 = 1110 = 14 unsigned?

Maybe it's an uber hack to select the very last number? :O

Sometimes you can't use 0 as an invalid number, but you still want something to indicate invalidity. Using -1 should give you the highest number possible which is nice to use if you don't want to lose have your range by using an int.

I'm not sure how standards compliant it is though.

The problem with using -1 to get the highest number of an unsigned value is that it doesn't work with all compilers. Several platforms have compilers that'll do weird things with that including clamping it to zero. The fact that it isn't well defined behavior makes it bad (although it does work that way with microsoft compilers).

If you want an unsigned int to have the highest possible value you could use this
#include <limits>

int main()
{
unsigned int foo( std::numeric_limits<unsigned int>::max() );
// Do something with foo here....
}