WinSock2.h generates expression before comma has no effect warning

Ilia - 1 Reputation point
2020-10-02T16:47:37.563+00:00

This is because of while (0, 0) in the following macros:

#define FD_CLR(fd, set) do { \
    u_int __i; \
    for (__i = 0; __i < ((fd_set FAR *)(set))->fd_count ; __i++) { \
        if (((fd_set FAR *)(set))->fd_array[__i] == fd) { \
            while (__i < ((fd_set FAR *)(set))->fd_count-1) { \
                ((fd_set FAR *)(set))->fd_array[__i] = \
                    ((fd_set FAR *)(set))->fd_array[__i+1]; \
                __i++; \
            } \
            ((fd_set FAR *)(set))->fd_count--; \
            break; \
        } \
    } \
} while(0, 0)

Original issue: https://developercommunity.visualstudio.com/content/problem/560279/winsock2h-generates-expression-before-comma-has-no.html

Now re-posting this https://aka.ms/AA539zf from Feedback Hub because it remained unresolved.

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,502 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Viorel 114.2K Reputation points
    2020-10-03T08:32:46.01+00:00

    Try this replacement:

    #define WORKAROUND_FD_CLR(fd, set) \
     __pragma( warning( push ) )  \
     __pragma( warning( disable : 4548 ) ) \
     FD_CLR(fd, set) \
     __pragma( warning( pop ) )
    
    0 comments No comments

  2. Drake Wu - MSFT 991 Reputation points
    2020-10-05T01:41:50.21+00:00

    Hi @Ilia - Which version of SDK you are using? I can see the while(0,0) has been fixed to the while(0) in SDK version 10.0.19613.0.

    #define FD_CLR(fd, set) do { \  
        u_int __i; \  
        for (__i = 0; __i < ((fd_set FAR *)(set))->fd_count ; __i++) { \  
            if (((fd_set FAR *)(set))->fd_array[__i] == fd) { \  
                while (__i < ((fd_set FAR *)(set))->fd_count-1) { \  
                    ((fd_set FAR *)(set))->fd_array[__i] = \  
                        ((fd_set FAR *)(set))->fd_array[__i+1]; \  
                    __i++; \  
                } \  
                ((fd_set FAR *)(set))->fd_count--; \  
                break; \  
            } \  
        } \  
    } while(0)  
    

    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.