[英]What is this string-literal in boolean expression idiom?
A coworker of mine was looking through one of our inherited code bases and found the following line: 我的一位同事正在查看我们继承的代码库之一,并找到以下行:
ATLASSERT( rtaddress == m_lRTAddress && "Creation settings should match FIFO" );
We don't understand what the purpose of the string literal is for; 我们不明白字符串文字的目的是什么; is it for more than just commenting?
这不仅仅是评论吗? The way I see it, if
rtaddress
does NOT equal m_lRTAddress
then the string will never be evaluated due to short circuiting. 我看到它的方式,如果
rtaddress
不等于m_lRTAddress
那么由于短路,字符串永远不会被评估。 If rtaddress
DOES equal m_lRTAddress
then the string literal will be evaluated but a string literal evaluated for a boolean expression will always return true
; 如果
rtaddress
等于m_lRTAddress
那么将对字符串文字进行求值,但对布尔表达式求值的字符串文字将始终返回true
; so what's the point? 那有什么意义呢?
我认为如果断言失败,你可以看到为什么添加断言的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.