dimanche 24 mai 2015

NULL check for nested pointers in a single if-statement

Struct {
    int a;
    struct sample *b;
} test;

int func(struct test *t1) {
  if (!t1 || !t1->b) {  // Is this statement ok?
    return _EINVAL
  }

  ...
}

Is it ok to NULL check for nested pointers in a single if-statement? Can I always assume that the left check(!t1 in my example) will be performed first?

Aucun commentaire:

Enregistrer un commentaire