Comma operator in conditional

I read in many places, but I really can't understand the specified behavior in conditional expressions.

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

But for this code, what was it supposed to do?

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

Was the batch file in IF an unnecessary argument or made any sense?

+5
source share
5 answers

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

+9
source

The comma operator executes the expression of the first element, discards the results, then evaluates the result as the last expression.

, partfile,bDeleted , partfile , , bDeleted

, -, (, ). , , .

. : Comma operator

+4
bool bDeleted = false;
if (partfile,bDeleted)
    partfile->PerformFileCompleteEnd(wParam);

if partfile, bDeleted, bDelete false, . : " ?". , - partfile->PerformFileCompleteEnd(wParam);, , , , , , . , , "if (partfile)", bDeleted , partfile->Perform... "" .

, ,...

#if 0
    if (partfile)
        partfile->PerformFileCompleteEnd(wParam);
#endif

... ...

#ifndef DONT_BYPASS_FILE_COMPLETE_PROCESSING_DURING_DEBUGGING
    if (partfile)
        partfile->PerformFileCompleteEnd(wParam);
#endif

... ...

if (partFile, !"FIXME remove this after debugging")
    partfile->PerformFileCompleteEnd(wParam);

(, "FIXME" "TODO" , #if 0 , , , debug vs release, ..).

+2

partfile , bDeleted . partfile - , .

+1

C/++. (.. Int x, int y;), (..: func (x, y)).

: . C/++ undefined.

result = x + y;

x y , x, y. , . , ,

result = x, y;

: .

, ...

+1

All Articles