0

I have a macro that I use at end of functions:

#define FN_EXIT(x) \
cout << "Message"; \
return x;

If I use it as FN_EXIT(1), it works okay. Can I use it as FN_EXIT() for void returning functions? If not, is there of a passing an argument that would work with return statement of a void function?

deeJ
  • 672
  • 11
  • 31
  • 6
    Avoid macros as much as you can. Especially buggy macros like yours (try doing something like `if (condition) FN_EXIT(y);` and see what happens). – Some programmer dude Nov 29 '16 at 07:17
  • Compiling with `-E` (gcc or clang) allows you to see what the compiler does with your macro. So you can try with no argument, and see that it will work for a `void` function. And you can try with an `if` statement and see why you shouldn't be doing this. – user3386109 Nov 29 '16 at 07:24

0 Answers0