Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why to write C code like "while((void)0, 0)"

Tags:

c

opencv

I read it from source code of opencv

#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) in here, but why to add "(void)0".

like image 542
no68 Avatar asked Nov 03 '14 16:11

no68


1 Answers

At a guess, it's probably to shut up a compiler warning like "condition is constant".

Since (what C classifies as) a constant expression can't include a comma operator, using one can convince some compilers that an expression isn't a constant (even in a case like this, where it really is).

like image 119
Jerry Coffin Avatar answered Oct 17 '22 05:10

Jerry Coffin