We know that multiline macros have to be inclosed in a do while(0) loop for them to be safely included anywhere in the code.
For example this is 100% safe:
#define swap( a , b ) \
do \
{ \
int t = a ; \
a = b ; \
b = t ; \
} \
while(0)
I would like to know if it is also safe to have a macro with a part of the code outside of the loop, and if it isn't, in what circumstances could problems occur.
#define swap( a , b ) \
int t ; \ //should be in the same scope where the macro was called and before the loop
do \
{ \
t = a ; \
a = b ; \
b = t ; \
} \
while(0)
Is there a safe way to achieve this, what would have to be changed or what rules should I follow if it isn't safe.