• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

why does this compile (c++)

TecHNooB

Diamond Member
if(function(a),false)
{
}

I made a boo boo and wrote that instead of

if(function(a, false))
{
}

I've done this a few times actually :|
 
Whatever function you are using has been overloaded as

type function(type a, bool b)

and

type function(type a)
 
The comma is an operator. You basically wrote

if(operator,(function(a), false))

I'm a little rusty but IIRC it typically returns the first argument unless it's been overridden to do something else.
 
Code:
for ( a=b=0; a<9; ++a, b+=5 ) ...
Okay, not the only way to iterate now, but it probably was quite expressive earlier.
 
The strict answer is that when the compiler sees...

if (expr) { }

... it evaluates expr to see if it is true, and if it is enters the conditional block of code. Your expression...

(function(a),false)

... is perfectly legal. The comma operator is used in C++ to separate expressions, so these two expressions are evaluated in order of precedence, i.e. left to right. Therefore the effect of the combined expression will be to, in order:

a) execute the function, passing a, and discarding the return value
b) return false to the if operator
 
Back
Top