Why did you define TRUE and FALSE macros like this?

Asked 2 years ago, Updated 2 years ago, 85 views

I saw in the book that TRUE/FALSE was defined like this, but I don't know the reason.

    #define TRUE  '/'/'/'
    #define FALSE '-'-'-'

What does this mean? Why can you write that one-zero?

c c++ boolean obfuscation macro

2022-09-22 22:26

1 Answers

'/'/'/' divides the characters '/' from each other.

Would it be easier to understand? Since a/a = 1, you can write true

'-'-'-' subtracts the letter -' from each other.

In other words,

That's it. Since a-a = 0, you can write false.

In fact, apart from what you can use, It's not a very good code.

It's not as readable as 0/1 Because the expression is not enclosed in parentheses.

If you run the following code because it is not enclosed in parentheses

#include <stdio.h>

#define TRUE  '/'/'/'
#define FALSE '-'-'-'

int main() {
        printf ("%d\n", 2 * FALSE);
        return 0;
}

Output - (45 on my computer)

#define TRUE ('/'/'/') Please put parentheses together.


2022-09-22 22:26

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.