user3593776
user3593776

Reputation: 1

How to use the following preprocessor statement

#define IS_THIS_CORRECT(X) if(X){}

I have this preprocessor statement defined in my project. I am trying to understand how to use this function.

Upvotes: 0

Views: 47

Answers (3)

Sourav Ghosh
Sourav Ghosh

Reputation: 134386

As this is currently written, there is very little possible meaningful use of it, except you want to handle only FALSE cases based on the value of X.

IMHO, you can re-write it as

#define IS_THIS_CORRECT(X) if(X)

then, you can use it like

 int p = 5;
 IS_THIS_CORRECT(X)
 {
      printf("yay !!!\n");
 }

Upvotes: 0

ForceBru
ForceBru

Reputation: 44886

#define IS_THIS_CORRECT(X) if(X){}

It can be used to check if X (any value) is not zero or is not an empty string etc. You can do the following

IS_THIS_CORRECT("Hello")
else puts("The string is empty");

You'd better surround X with another pair of braces for more safety:

#define IS_THIS_CORRECT(X) if((X)){}

I suggest you to rename this preprocessor statement as IT_IS_CORRECT or even IS_CORRECT for more readability.

Upvotes: 1

Wintermute
Wintermute

Reputation: 44063

I'm guessing, but the only way this makes any sense to me is if it's supposed to be used as

IS_THIS_CORRECT(foo) else { do_something(); }

Still weird, though.

Upvotes: 0

Related Questions