Ubik

Sign in to follow this  
  • entries
    101
  • comments
    122
  • views
    57908

#gamedev

Sign in to follow this  
Will F

227 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.
Sign in to follow this  


6 Comments


Recommended Comments

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.

Share this comment


Link to comment
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?

Share this comment


Link to comment
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

Share this comment


Link to comment
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.

Share this comment


Link to comment
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).

Share this comment


Link to comment
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....
}

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now