TRUE和FALSE宏的奇怪定义

本文翻译自: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 . 请向我解释这些将如何工作为TRUEFALSE


#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. 杰伊的回答

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值