Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comma operator in a conditional

I have read in a lot of places but I really can't understand the specified behavior in conditionals.

I understand that in assignments it evaluates the first operand, discards the result, then evaluates the second operand.

But for this code, what it supposed to do?

CPartFile* partfile = (CPartFile*)lParam;
ASSERT( partfile != NULL );
bool bDeleted = false;
if (partfile,bDeleted)
    partfile->PerformFileCompleteEnd(wParam);

The partfile in the IF was an unnecessary argument, or it have any meaning?

like image 305
bratao Avatar asked Jan 24 '11 04:01

bratao


People also ask

Can we use comma in if condition?

Punctuating Conditional SentencesUse a comma after the if-clause when the if-clause precedes the main clause. If I'd had time, I would have cleaned the house. If the main clause precedes the if-clause, no punctuation is necessary.

What are the uses of comma and conditional operator?

The Comma as an Operator We use the comma in the form of an operator when we want to assign multiple numbers of values to any variable in a program with the help of a comma.

What is the comma operator in C?

In the C and C++ programming languages, the comma operator (represented by the token , ) is a binary operator that evaluates its first operand and discards the result, and then evaluates the second operand and returns this value (and type); there is a sequence point between these evaluations.

What operators are used in conditional statements?

There are three conditional operators: && the logical AND operator. || the logical OR operator. ?: the ternary operator.


1 Answers

In this case, it is an unnecessary expression, and can be deleted without changing the meaning of the code.

like image 146
Raph Levien Avatar answered Sep 30 '22 09:09

Raph Levien