Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is this string-literal in boolean expression idiom?

Tags:

c++

c

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. 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; so what's the point?

like image 520
SiegeX Avatar asked May 18 '12 23:05

SiegeX


1 Answers

I think it's so that if the assert fails you can see the reason why the assert was added.

like image 198
Mark Byers Avatar answered Sep 17 '22 18:09

Mark Byers