lundi 3 octobre 2016

C if statement comparing two integer variables to the same constant

I am trying to compare two integer variables to a same constant. Apparently in this case, both variables are having same default values and i tried to simplify the comparison statement like this:

if (po->app_tag == po->inst_id == 0) return 1;

It dint work.. :S

I had to code it lie: if ((po->app_tag == 0) && (po->inst_id == 0)) return 1;

To make it work. Anyone can explain me the difference between the two? Somehow i feel that C compiler should have a provision for this kind of syntax when it comes to comparison of two integer variables. I can be wrong asking for it.. :), but want to understand a reason.. why am I wrong here.

Aucun commentaire:

Enregistrer un commentaire