Handmade Hero»Forums»Code
Luiz Heringer
4 posts
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)))
{
   ...
}

Mārtiņš Možeiko
2570 posts / 2 projects
Is may or may not redundant?
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)
    {
        ...
    }
}
Luiz Heringer
4 posts
Is may or may not redundant?
Edited by Luiz Heringer on
Now I get it. Thanks man.