O_O
O_O

Reputation: 4477

Is this a valid C command/instruction?

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!

Upvotes: 5

Views: 179

Answers (5)

Will Vousden
Will Vousden

Reputation: 33358

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.

Upvotes: 7

Jay Conrod
Jay Conrod

Reputation: 29691

Yes, this is the same as:

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

The assignment operator (=) can be chained just like any other operator. It is evaluated from right to left, and each evaluation returns the value that was assigned. So this is equivalent to the following two statements.

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

Upvotes: 6

codaddict
codaddict

Reputation: 455000

It is equivalent to:

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

Upvotes: 2

user229044
user229044

Reputation: 239290

White space isn't important. The line really reads

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

Which is equivalent to

int a;
int b;

a = b = 0;

Upvotes: 2

Will Tate
Will Tate

Reputation: 33509

The whitespace is ignored and its all evaluated as...

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

Upvotes: 1

Related Questions