comma operator

Michael Zehr tada at athena.mit.edu
Tue Aug 1 23:41:59 AEST 1989


In article <918 at helios.toronto.edu> dooley at helios.physics.utoronto.ca (Kevin Dooley) writes:
>Can anybody tell me if there is a usage where the comma is 'better'.
>By this I mean are there any places where using a comma makes the 
>code more readable, efficient, produce cleaner/faster assembler (I
>know this is compiler dependant).  It's just that I've never seen a
>program with the comma operator where I didn't scream and edit it out.
>Am I being hopelessly pedestrian here?
>

I agree with you completely.  People seem to use the comma operator to
save lines of code and bytes of text files.  It rarely makes a
difference in the compiled code, and it does make it harder to read.

If you debate the "harder to read" bit, consider this -- the comma
essentially is like putting two statements on one line.  would you
rather read code like:
  puts("it broke."); exit(2);

than:
  puts("it broke.");
  exit(2);

I will qualify the "no comma" rule, though -- sometimes a comma is
required in a macro in order to allow the macro to "return" a value.  of
course, this isn't making code much harder to read because it only
appears in one place, and there is no other solution given the syntax of
tha language.

-michael j zehr



More information about the Comp.lang.c mailing list