Macro translation

This is a discussion on Macro translation within the C++ Programming forums, part of the General Programming Boards category; I am trying to analyze some code and I ran into this giant macro. Can someone please translate this into ...

  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
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,762
    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, 10:13 AM
  2. Macro problem
    By TriKri in forum C Programming
    Replies: 6
    Last Post: 05-14-2010, 03:52 AM
  3. Replies: 2
    Last Post: 04-12-2010, 01:57 PM
  4. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 02:29 PM
  5. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 11:17 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21