Is may or may not redundant?

Is Casey checking two times the DirectSoundCreate? Like, checking all the function, and checking with those parameters in specific? What is going on with this statement?

1
2
3
4
if(DirectSoundCreate && SUCCEEDED(DirectSoundCreate(0, &directSound, 0)))
{
   ...
}

DirectSoundCreate is a pointer (function pointer).

"DirectSoundCreate" tests if pointer is not NULL. It is equivalent to following expression "DirectSoundCreate != NULL".

"SUCCEEDED(DirectSoundCreate(0, &directSound, 0))" is calling this function pointer and passing result to SUCCEEDED macro. This macro expands to something like this: "DirectSoundCreate(0, &directSound, 0) == S_OK".

So if statement executes following:
1
2
3
4
5
6
7
if (DirectSoundCreate != NULL)
{
    if (DirectSoundCreate(0, &directSound, 0) == S_OK)
    {
        ...
    }
}
Now I get it. Thanks man.

Edited by Luiz Heringer on