lundi 14 décembre 2015

Does the C compiler combine if statements if they return the same thing?

I'm trying to understand how a compiler will optimize two if statements that return the same value. Consider the following code at the top of a function:

if (some_ptr == NULL) {
    return -1;
}

if (some_other_ptr == NULL) {
    return -1;
}

Will the two if statements be combined into one check that is equivalent to:

if (some_ptr == NULL || some_other_ptr == NULL) {
    return -1;
}

Thanks.

Aucun commentaire:

Enregistrer un commentaire