Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is this a valid C command/instruction?

Tags:

c

syntax

I am looking over some code someone else did and I see this:

            if (numDetects == 0) {

                Table[Index].minF = 

            Table[Index].maxF = F;

            }

The Table[Index].minF = blank does not make any sense to me. I've never seen this in my life. BUT the code does compile and run, so could someone explain to me if this is possible or not to just have a equal sign left hanging there? Thanks!

like image 700
O_O Avatar asked Mar 01 '11 18:03

O_O


1 Answers

Yes; C doesn't care about the white space between the first line and the second, so it sees it as

Table[Index].minF = Table[Index].maxF = F;

It's syntactically equivalent to

Table[Index].minF = (Table[Index].maxF = F);

since the assignment operator = not only assigns the left-hand side to the right-hand side, but also returns the value that was assigned. In this case, that return value is then in turn assigned to the outer left-hand side.

like image 156
Will Vousden Avatar answered Nov 15 '22 05:11

Will Vousden