Is it possible to use tilde (~) in C preprocess directive in the following way?

#define a 1
#if ~a==0
...
#endif

Generally, I want to know how we can ~ in preprocessor directives?

Have you tried that code? I mean, a simple test program would have answered your question in far less time than it took for me to notice it and answer. But yes, you can use bitwise NOT in a preprocessor directive.

Thank you for your response. That program does not work but the reason I asked was maybe my example is not correct enough. Is there any reference or something I could read why I could not use it that way?

That program does not work

How does it "not work"? Are you getting a compilation error or does it simply not produce the result you expected? The reason I ask is that ~1 is -2 (in a two's complement system), not 0.

Yes, I mean it returns -2.

Yes, I mean it returns -2.

Then it's working properly and the problem is your understanding of the bitwise NOT operator.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.