comma operator

Dave Decot decot at hpisod2.HP.COM
Thu Aug 3 09:32:43 AEST 1989


> The comma operator's main legitimate use is in the definition of macros
> that are expected to act like function calls but perform actions too
> complex for a single (non-comma) expression.

Another convenient use of the comma operator is in for loops that vary
two variables at once:

    for (count = 0, p = Head; count < MAX && p != NULL; ++count, p = p->next)
    {
	...
    }

Moving one of the initializations above the for statement and one of
the increments into the loop body would eliminate the commas, but would
also make the dual nature of the loop less clear.

Dave Decot



More information about the Comp.lang.c mailing list