Can replacing statements with expressions with the C ++ comma operator allow more optimized compilation?

The C ++ comma operator is used to combine individual expressions, resulting in the result of the value of the last expression executed.

For example, skeletal code (6 operators, 6 expressions):

step1;
step2;
if (condition)
    step3;
    return step4; 
else
    return step5;

Can be rewritten to: (1 instruction, 6 expressions)

return step1, 
       step2,
       condition?
          step3, step4 : 
          step5;

I noticed that step-by-step debugging of such code is not possible, since the expression chain seems to be executed as a whole. Does this mean that the compiler is capable of performing special optimizations that are impossible with the traditional approach to description (especially if the steps are constant or inline)?

. ! , .

+3
3

" ", / . : . , , . , , : , , . , , "", - . - , , " " , . .

, , . , - , , . , , , .

, , , , . " ", , , . , , , , . , - , " hokey-cokey", " , " .

+5

, , ++ - , , , . ( , .)

, , , , - , . ( ? , my_func((++i, y), x).)

"" , , - for:

for (int i = 0, j = 0; 
     i < 10 && j < 12; 
     i += j, ++j) // each time through the loop we're tinkering with BOTH i and j
{
}
+1

. / , , , , .

OTOH, , . , .;)

:

  • , , , .
  • , , ,
  • , .:)
0

Source: https://habr.com/ru/post/1738852/


All Articles