Thread: Macro translation

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

    Macro translation

    I am trying to analyze some code and I ran into this giant macro. Can someone please translate this into an equivalent C function?

    Code:
    #define BOX_ON_PLANE_SIDE(emins, emaxs, p)						\
    	(((p)->type < 3)?								\
    	(										\
    		((p)->dist <= (emins)[(p)->type])?					\
    			1								\
    		:									\
    		(									\
    			((p)->dist >= (emaxs)[(p)->type])?				\
    				2							\
    			:								\
    				3							\
    		)									\
    	)										\
    	:										\
    		BoxOnPlaneSide( (emins), (emaxs), (p)))

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Notice that when p->type is greater than or equal to 3 it calls something else called BoxOnPlaneSide(). Otherwise it resolves to one of the precalculated answers, 1, 2, or 3. That's pretty much all it does. The ternary operator ?: is really just another way to write an if else as a statement, and I think it is being abused here.

  3. #3
    Registered User
    Join Date
    May 2009
    Location
    Look in your attic, I am there...
    Posts
    92
    Great, thats all I needed to know. Thanks for the help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem building Quake source
    By Silvercord in forum Game Programming
    Replies: 16
    Last Post: 07-11-2010, 09:13 AM
  2. Macro problem
    By TriKri in forum C Programming
    Replies: 6
    Last Post: 05-14-2010, 02:52 AM
  3. Replies: 2
    Last Post: 04-12-2010, 12:57 PM
  4. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  5. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 10:17 AM