5

#define AUDIOLB_EXIT_ON_ERROR(hres) \
if (FAILED(hres)) { goto Exit; }

#define AUDIOLB_SAFE_RELEASE(punk) \
if ((punk) != NULL) \
{ (punk)->Release(); (punk) = NULL; }

Looking through old audio code I wrote. Found these macros. Will most likely reuse for a new project. It works damnit!

Do you feel lucky?!

Comments
  • 0
    pointers can be implicitly converted to booleans, you don't need to compare to NULL
  • 1
    I wanted it to be obvious the test was for null.
  • 1
    I think you should wrap your macro bodies in a do { ... } while(0) block to avoid dangling else and other potential unintended behavior
  • 0
    Is there any chance that you can replace the goto statement with something else?
  • 1
    @offworld or add "else ;" if that's a concern
  • 1
    @offworld That is an interesting idea. I could slap just some braces {} around it, or put a else{} on the end too. Thanks.
  • 0
    @orhun I am not sure I can get rid of the goto. I will look into some potential RAII for this.
Add Comment