Why write C code like "while ((void) 0, 0)"

I read it from opencv source code

#define IPP_FILTER_MEDIAN_BORDER(ippType, ippDataType, flavor) \ do \ { \ if (ippiFilterMedianBorderGetBufferSize(dstRoiSize, maskSize, \ ippDataType, CV_MAT_CN(type), &bufSize) >= 0) \ { \ Ipp8u * buffer = ippsMalloc_8u(bufSize); \ IppStatus status = ippiFilterMedianBorder_##flavor(src.ptr<ippType>(), (int)src.step, \ dst.ptr<ippType>(), (int)dst.step, dstRoiSize, maskSize, \ ippBorderRepl, (ippType)0, buffer); \ ippsFree(buffer); \ if (status >= 0) \ { \ CV_IMPL_ADD(CV_IMPL_IPP); \ return; \ } \ } \ setIppErrorStatus(); \ } \ while ((void)0, 0) 

I can understand while (0) here, but why add "(void) 0".

+7
c opencv
source share
2 answers

Guess probably to shut up a compiler warning, such as "condition is constant".

Since (what C classifies as), a constant expression cannot include a comma operator using one, you can convince some compilers that the expression is not a constant (even in that case, where it really is).

+13
source share

I am not 100% sure if this is the reason, but I know that if you do

 #define FOO do{ doStuff(); } while(0) 

And then turn on the MSVC 4 (/ W4) compiler warning level, you will get warning C4127. But if you do this:

 #define FOO do{ doStuff(); } while((void)0,0) 

warning C4127 goes away. Perhaps there are other reasons for using while((void)0,0) rather than while(0) , I'm not sure ...

+1
source share

All Articles