Thread: Question about if statement

  1. #1
    Registered User
    Join Date
    May 2009
    Location
    Look in your attic, I am there...
    Posts
    92

    Question about if statement

    I understand that C having no boolean values uses Ints and Null checks in if statements. However, I came across some code and would like to know why the programmer chose to use null check if statements. Is it only error checking or is it something to avoid function overloading?

    Code:
    void AngleVectors (vec3_t angles, vec3_t forward, vec3_t right, vec3_t up)
    {
    	float		angle;
    	static float		sr, sp, sy, cr, cp, cy;
    	// static to help MS compiler fp bugs
    
    	angle = angles[YAW] * (M_PI*2 / 360);
    	sy = sin(angle);
    	cy = cos(angle);
    	angle = angles[PITCH] * (M_PI*2 / 360);
    	sp = sin(angle);
    	cp = cos(angle);
    	angle = angles[ROLL] * (M_PI*2 / 360);
    	sr = sin(angle);
    	cr = cos(angle);
    
    	if (forward)
    	{
    		forward[0] = cp*cy;
    		forward[1] = cp*sy;
    		forward[2] = -sp;
    	}
    	if (right)
    	{
    		right[0] = (-1*sr*sp*cy+-1*cr*-sy);
    		right[1] = (-1*sr*sp*sy+-1*cr*cy);
    		right[2] = -1*sr*cp;
    	}
    	if (up)
    	{
    		up[0] = (cr*sp*cy+-sr*-sy);
    		up[1] = (cr*sp*sy+-sr*cy);
    		up[2] = cr*cp;
    	}
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > // static to help MS compiler fp bugs
    What kind of lame comment/excuse is this?
    At the very least, it should cite specific compiler versions and bug report numbers.

    The NULL checks allow users to do things like this:
    AngleVectors( angles, result, NULL, NULL );

    It's a fairly common technique for providing a generalised function, with the option to omit returning results which you're not interested in at the moment.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    May 2009
    Location
    Look in your attic, I am there...
    Posts
    92
    > // static to help MS compiler fp bugs
    What kind of lame comment/excuse is this?
    At the very least, it should cite specific compiler versions and bug report numbers.
    Lol yea, this code is actually part of the quake 2 engine its filled with comments like that.

    Anyway, I had a feeling it was a way to get around function overloading. Thanks for the clarification.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about break in switch statement
    By alone2002dj in forum C Programming
    Replies: 1
    Last Post: 12-09-2007, 08:42 PM
  2. Quick IF statement question (beginner)
    By jim.rattlehead in forum C Programming
    Replies: 23
    Last Post: 11-29-2007, 06:51 AM
  3. Design layer question
    By mdoland in forum C# Programming
    Replies: 0
    Last Post: 10-19-2007, 04:22 AM
  4. Very simple question, problem in my Code.
    By Vber in forum C Programming
    Replies: 7
    Last Post: 11-16-2002, 03:57 PM
  5. Uh-oh! I am having a major switch problem!
    By goodn in forum C Programming
    Replies: 4
    Last Post: 11-01-2001, 04:49 PM