Unclear behavior of "," operator in C -


in given code found following sequence,

data = poc_p_status, te_ok; 

i don't understand mean.

does data element receive first or second element or else?

update:

i read somewhere behavior this,

if write that:

if(data = poc_p_status, te_ok) { ... }

then teh if clause true if te_ok true.

what mean?

it's equivalent following code:

data = poc_p_status; te_ok; 

in other words, assigns poc_p_status data , evaluates te_ok. in first case, expression stands alone, te_ok meaningful if it's macro side effects. in second case, expression part of if statement, evaluates value of te_ok. statement rewritten as:

data = poc_p_status; if (te_ok) { ... } 

from c11 draft (http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf) :

the left operand of comma operator evaluated void expression; there sequence point after evaluation. right operand evaluated; result has type , value. if attempt made modify result of comma operator or access after next sequence point, behavior undeļ¬ned.

that means in expression:

a, b 

the a evaluated , thrown away, , b evaluated. value of whole expression equal b:

(a, b) == b 

comma operator used in places multiple assignments necessary 1 expression allowed, such for loops:

for (int i=0, z=length; < z; i++, z--) {     // things } 

comma in other contexts, such function calls , declarations, not comma operator:

int func(int a, int b) {...}               ^               |               not comma operator  int a, b;      ^      |      not comma operator 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -