A fast definition

I usually write :
if(a >= min && a <= max)//Just a general case
An another similar & popular case :
if(a != 1 && a != 2 && a != 3...)
Now I can solve this problem by making a new definition :
#define InRange(num,min,max)(num >= min && num <= max)
The code now is :
if(InRange(a,min,max))//For all cases (float, double, int,...)

Some useful & instant definition :
1
2
3
#define HalfRange(num,min,max)(num > min && num < max)
#define min(x,y) ((x) < (y)) ? (x) : (y)
#define max(x,y) ((x) > (y)) ? (x) : (y) 


What do you think?
Last edited on
As you seem to be using Visual Studio, I'd recomend not using the names min and max. There are macros with those names.
What do you think about this function:
1
2
inline bool Text_CheckChar(char chrInp,const char *strAllow){
while(strAllow){if(chrInp == (*strAllow))return true;strAllow++;}return false;}
Your function has one problem : if strAllow is not NULL and chrInp is not found, the loop never ends.

If you're using C strings, that can be corrected by modifying the loop condition :
while(strAllow && *strAllow)
Topic archived. No new replies allowed.