delorie.com/archives/browse.cgi | search |
X-Recipient: | archive-cygwin AT delorie DOT com |
DKIM-Filter: | OpenDKIM Filter v2.11.0 sourceware.org BD1A53857C5B |
DKIM-Signature: | v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com; |
s=default; t=1596391743; | |
bh=WRnsrJ4XvkyN/IsfpFYkNl5PtHepv/kmWyYsRuDMlfo=; | |
h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: | |
List-Help:List-Subscribe:From:Reply-To:From; | |
b=x/rgvtRpaQF6WwTgSv55lR2z7R9L/uPxIGQxwWR/l+iTH9KjhepehvDUMhh2Sj+Gh | |
wG18qc6XmBdfu4XX4h6zlfIV8EZ/xV2ZUWpz2nCiEQYlHGhaJAQjnNsTGpuDlO6fU8 | |
/SkWzMroemKxxUb1bxkw8r9wp7Nvvc2BmunG5Qk8= | |
X-Original-To: | cygwin AT cygwin DOT com |
Delivered-To: | cygwin AT cygwin DOT com |
DMARC-Filter: | OpenDMARC Filter v1.3.2 sourceware.org A63773858D35 |
X-Google-DKIM-Signature: | v=1; a=rsa-sha256; c=relaxed/relaxed; |
d=1e100.net; s=20161025; | |
h=x-gm-message-state:to:from:subject:message-id | |
:disposition-notification-to:date:user-agent:mime-version | |
:content-transfer-encoding:content-language; | |
bh=4upJWVzHaieoCUssAa/wJ/n83Fn520vKMW2YU/0jHhM=; | |
b=nko+uKOoNUssVOFnvApJjkbIMdobK1l8duwiENXQIcTUCICU8TETKwbSEIEOZQzmBk | |
kGgPev/DWHHZjO1mnIH8Uvfxc3azHuWwYjapVkZLf6V6xTNdNF7zm/8m0chivYN2E07f | |
rOGqxOiN4+R6F251UN16Wk28z3krAyXbXuB7DIAGPyy0Z3OAN8Fv0rDUYto/91HvGU0V | |
AaMjYl3hI3IYgnfpxMfxN4RZWiaMQ0jY3vAV0uSPYufKoFNc65A5liHtPA65TkAS0rk0 | |
mJ07afpCRpkTGmJYs0ypUlaUGHggIciOnNMMfSxHVDWR/ixM7bmqIIT0B0Iprw6rlnyh | |
H4NQ== | |
X-Gm-Message-State: | AOAM531yyulUlSBUNXQr2S9Kv8HcEmROp33DWxQ7EVjIJVy+9ipwhBlo |
ID4H9KLWCqERwef/OCdm7sly1HKQjpE= | |
X-Google-Smtp-Source: | ABdhPJyC650aFiCdAwZAfnuFPL3IWFa/B3XRRTOdU91CCyTdtxbyV0brtFj3W7Oq4giuQpHrNA8RcQ== |
X-Received: | by 2002:adf:f0ce:: with SMTP id x14mr11446041wro.137.1596391739327; |
Sun, 02 Aug 2020 11:08:59 -0700 (PDT) | |
To: | cygwin AT cygwin DOT com |
Subject: | FD_{SET,ISSET,CLR} macros from sys/select.h triggerring gcc's |
-Wsign-conversion warnings | |
Message-ID: | <1f188b7e-6dc4-73af-e458-013760210469@gmail.com> |
Date: | Sun, 2 Aug 2020 20:08:57 +0200 |
User-Agent: | Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 |
Thunderbird/68.8.0 | |
MIME-Version: | 1.0 |
X-Spam-Status: | No, score=-1.2 required=5.0 tests=BAYES_00, BODY_8BITS, |
DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, | |
GB_FREEMAIL_DISPTO, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, | |
TXREP autolearn=ham autolearn_force=no version=3.4.2 | |
X-Spam-Checker-Version: | SpamAssassin 3.4.2 (2018-09-13) on |
server2.sourceware.org | |
X-BeenThere: | cygwin AT cygwin DOT com |
X-Mailman-Version: | 2.1.29 |
List-Id: | General Cygwin discussions and problem reports <cygwin.cygwin.com> |
List-Archive: | <https://cygwin.com/pipermail/cygwin/> |
List-Post: | <mailto:cygwin AT cygwin DOT com> |
List-Help: | <mailto:cygwin-request AT cygwin DOT com?subject=help> |
List-Subscribe: | <https://cygwin.com/mailman/listinfo/cygwin>, |
<mailto:cygwin-request AT cygwin DOT com?subject=subscribe> | |
From: | Petr Skocik via Cygwin <cygwin AT cygwin DOT com> |
Reply-To: | Petr Skocik <pskocik AT gmail DOT com> |
Sender: | "Cygwin" <cygwin-bounces AT cygwin DOT com> |
X-MIME-Autoconverted: | from base64 to 8bit by delorie.com id 072I9U6J024022 |
Example: #include <sys/select.h> void f(int X) {    fd_set set;    FD_ZERO(&set);    FD_SET(X,&set);    FD_CLR(X+1,&set);    (void)FD_ISSET(X+2,&set); } causes fds.c:7:2: warning: conversion to ‘long unsigned int’ from ‘int’ may change the sign of the result [-Wsign-conversion]  FD_SET(X,&set);  ^~~~~~ fds.c:7:2: warning: conversion to ‘long unsigned int’ from ‘int’ may change the sign of the result [-Wsign-conversion] fds.c:7:2: warning: conversion to ‘long unsigned int’ from ‘long int’ may change the sign of the result [-Wsign-conversion] fds.c:8:2: warning: conversion to ‘long unsigned int’ from ‘int’ may change the sign of the result [-Wsign-conversion]  FD_CLR(X+1,&set);  ^~~~~~ fds.c:8:2: warning: conversion to ‘long unsigned int’ from ‘int’ may change the sign of the result [-Wsign-conversion] fds.c:8:2: warning: conversion to ‘long unsigned int’ from ‘long int’ may change the sign of the result [-Wsign-conversion] fds.c:9:8: warning: conversion to ‘long unsigned int’ from ‘int’ may change the sign of the result [-Wsign-conversion]  (void)FD_ISSET(X+2,&set);        ^~~~~~~~ fds.c:9:8: warning: conversion to ‘long unsigned int’ from ‘int’ may change the sign of the result [-Wsign-conversion] fds.c:9:8: warning: conversion to ‘long unsigned int’ from ‘long int’ may change the sign of the result [-Wsign-conversion] on gcc with -Wconversion -Wsign-conversion. The problem is caused by the following macros:    # define   NFDBITS   (sizeof (fd_mask) * 8)   /* bits per mask */    # define   FD_SET(n, p)   ((p)->fds_bits[(n)/NFDBITS] |= (1L << ((n) % NFDBITS)))    # define   FD_CLR(n, p)   ((p)->fds_bits[(n)/NFDBITS] &= ~(1L << ((n) % NFDBITS)))    # define   FD_ISSET(n, p)   ((p)->fds_bits[(n)/NFDBITS] & (1L << ((n) % NFDBITS))) int-casting the sizeof and using 1UL instead of 1L fixes the problem: #include <sys/select.h> #if __CYGWIN__    //current defs # define   NFDBITS   (sizeof (fd_mask) * 8)   /* bits per mask */    # define   NFDBITS   (sizeof (fd_mask) * 8)   /* bits per mask */    # define   FD_SET(n, p)   ((p)->fds_bits[(n)/NFDBITS] |= (1L << ((n) % NFDBITS)))    # define   FD_CLR(n, p)   ((p)->fds_bits[(n)/NFDBITS] &= ~(1L << ((n) % NFDBITS)))    # define   FD_ISSET(n, p)   ((p)->fds_bits[(n)/NFDBITS] & (1L << ((n) % NFDBITS)))    #if CYGWIN_FD_REDEFS    #undef NFDBITS    #undef FD_SET    #undef FD_CLR    #undef FD_ISSET    //redefs that don't trigger gcc's -Wsign-conversion    # define   NFDBITS   ((int)sizeof (fd_mask) * 8)   /* bits per mask */    # define   FD_SET(n, p)   ((p)->fds_bits[(n)/NFDBITS] |= (1UL << ((n) % NFDBITS)))    # define   FD_CLR(n, p)   ((p)->fds_bits[(n)/NFDBITS] &= ~(1UL << ((n) % NFDBITS)))    # define   FD_ISSET(n, p)   ((p)->fds_bits[(n)/NFDBITS] & (1UL << ((n) % NFDBITS)))    #endif #endif void f(int X) {    fd_set set;    FD_ZERO(&set);    FD_SET(X,&set);    FD_CLR(X+1,&set);    (void)FD_ISSET(X+2,&set); } Regards, Petr Skocik -- Problem reports: https://cygwin.com/problems.html FAQ: https://cygwin.com/faq/ Documentation: https://cygwin.com/docs.html Unsubscribe info: https://cygwin.com/ml/#unsubscribe-simple
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |