本文翻译自:Strange definitions of TRUE and FALSE macros
I have seen the following macro definitions in a coding book. 我在编码书中看到了以下宏定义。
#define TRUE '/'/'/'
#define FALSE '-'-'-'
There was no explanation there. 那里没有解释。
Please explain to me how these will work as TRUE
and FALSE
. 请向我解释这些将如何工作为TRUE
和FALSE
。
#1楼
参考:https://stackoom.com/question/2IvEh/TRUE和FALSE宏的奇怪定义
#2楼
It's just another way of writing 这只是另一种写作方式
#define TRUE 1
#define FALSE 0
The expression '/'/'/'
will divide the char value of '/'
by itself, which will give 1 as a result. 表达式'/'/'/'
将自己的char值除以'/'
,这将得到1作为结果。
The expression '-'-'-'
will substract the char value of '-'
from itself, which will give 0 as a result. 表达式'-'-'-'
'-'
将从自身中减去'-'
的char值,结果将得0。
Brackets around the whole define
expressions are missing though, which can lead to errors in the code using these macros. 虽然缺少整个define
表达式的括号,但这可能导致使用这些宏的代码出错。 Jay's answer adresses that pretty well. 杰伊的回答