Allen Babb

CW 5.9.0 (SE) - Defining an if-else macro in C

Discussion created by Allen Babb on Sep 2, 2011
Latest reply on Sep 8, 2011 by Allen Babb

Hi all,


For my application, I need to do quite a bit of saturation on some data values, so I thought I would be a good idea to turn this:


if( x > ceiling)  y = ceiling;else if(x < floor)  y = floor;else  y = x;

 into a #define macro. Problem is, whenever I try to do so, I get at least 2 errors saying that I messed up somewhere.


What is the (proper) way of doing this, and is it considered good code practice? (I'd like to not piss off my successor any more than necassary :smileywink: )