Unusual C ++ Syntax

Possible duplicate:
C ++ Comma Operator

About a year ago, I noticed some obscure syntax in the coding project that I was working on:

table_value = table_index += 2, valueFromTable(table_index);

Does anyone recognize this ?, it's like an assignment with an extra expression. This is compiled in the entire cross-platform compiler suite, so I'm pretty sure it is a valid C ++, but I have never seen anything like it.

Any insight would be appreciated.

Gearoid

EDIT: there is a working code:

#include <iostream>
using namespace std ;

int valueFromTable(int a) { return a ; }

int main()
{
  int table_index = 0 ;
  int table_value = table_index += 2, valueFromTable(12);
  cout<<table_value<<endl;
  return 0 ;
}
+3
source share
1 answer

This is a comma operator .
These are standard C and C ++, but frowned heavily.

It evaluates both arguments and returns the result of the second.

+6

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


All Articles