#gamedev

posted in Ubik
Published June 06, 2006
Advertisement
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.
Previous Entry back to work
Next Entry ...
0 likes 6 comments

Comments

Mushu
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.
June 06, 2006 07:18 AM
Will F
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?
June 06, 2006 07:46 AM
Metorical
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
June 06, 2006 08:57 AM
rick_appleton
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.
June 06, 2006 09:18 AM
blue_knight
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).
June 06, 2006 12:56 PM
Will F
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....
}
June 06, 2006 06:15 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement

Latest Entries

XNA

1529 views

...

642 views

Physics demo

1255 views

Console launch...

1091 views

New project

1450 views

b day

1108 views

Source control

1277 views

More on Inform 7

1062 views

Logging

1208 views

Lines of code

1274 views
Advertisement