In our recent project i write a macro that will continue on given condition and as explained here C multi-line macro: do/while(0) vs scope block I tried to use do--while to achieve that. Below is sample code to illustrate that :
#define PRINT_ERROR_AND_CONTINUE_IF_EMPTY(dummy,dummystream,symbol,errorString) \
do{ \
if(dummy.empty())\
{\
dummyStream<<symbol<<",Failed,"<<errorString<<std::endl;\
continue;\
}\
}while(0)
int main()
{
int x =9;
std::ofstream& ofsReportFile;
while(x>5)
{
std::string str;
PRINT_ERROR_AND_CONTINUE_IF_EMPTY(str,ofsReportFile,"Test","Test String is Empty");
std::cout<<x<<std::endl;
x--;
}
return 0;
}
However this is not working as expected and the reason may be continue statement inside do while so question how to write multi-line macro with continue statement and also user of that macro can call it like CONTINUE_IF_EMPTY(str);