TooTiredToDrink TooTiredToDrink - 1 month ago 9
C Question

C strange if statement syntax

I saw this if statement and I am not sure exactly how that works, what is being compared with what? Is there a lack of && or ||? The parens are confusing me.

if ((list->func)((list->head)->dataPointer, newOb) < 0) {

Answer

what is being compared with what? The parens are confusing me.

The result of the part between if( and ) is being compared with 0, like in every if statement.

Is there a lack of && or ||?

I don't see any && or ||

The parens are confusing me.

What (list->func)((list->head)->dataPointer, newOb) does is (not necessarily in this order):

  • Evaluate list->func
  • Evaluate (list->head)->dataPointer
  • Call list->func passing the two arguments (list->head)->dataPointer and newOb.

The result of this is then compared to 0 because it's what's between the if( and ).