X-Recipient: archive-cygwin AT delorie DOT com X-Original-To: cygwin AT cygwin DOT com Delivered-To: cygwin AT cygwin DOT com DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0CA43385841B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=1wU4dSRktrLEafep13DTS2esTRe5anY+Dh8F4MzMRZc=; b=QEc/LEFExaw9nU2/qGIEMfOKRL0M/h6UW/9/81W2KCLy2k17+rJH9De13QpP7wOvut +BZaNSBrTFJUNx966GZTIVzd+vgy6gYDMkf6lT8tHRn0Aj7BbmLszKUe0F6LSO8nOTkM TKShpqsOQh1RbHLDyjFnv88ngGtdgJWSRjt2JV0LATvazIJVac52nwYRO7q3TyQ4JF0r 7u7ov1eUjdxnqHQw+cDCka4uAIeHZzt5gFMFYUA1RenvbigcfYMVHpI5PZ+mLQQAU4jn f1xpAJREbPGLfGD8vX3r/Q6np6Vs3AhmNM+GAYRWM6dmwBdn5I92Dko8fl7b8L4LN7Rk 49ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=1wU4dSRktrLEafep13DTS2esTRe5anY+Dh8F4MzMRZc=; b=10G4tAKOVG6Wjcl1hkdbLG8YXQmPVi9RenGKIONUlVSfiMvpxQbVVNyEMvCYlM7QoT JUItDKmk57BUaGVLegmUGzQIpjdMxc8JIQjSMG0y9ntuaI82hR/DJox359pP6dDuqswb lSIcjoW1ANhI0nzURSBN/BqxW3mDGyQcxxZt3IR42L7UCIBp/QRjT6SdhdO1a3EI9e8L yfE31d8rnIt+HED70QpswqpGMBKAefcrKCfyTYRiBk5kq8hBdiIhQ/LOMLZEP0q6B9c6 YmrBHVwVqsUtWyNQV1SpapWOjRwlbsWTJ5ftOtNbYXHnPXZiaAHgfW693a4UlMfEfk5C gG0A== X-Gm-Message-State: AOAM532bSORA1nl3Eiu+rmxCS78UAMVermHl/UUQCvL+Q5eVtyMsUWhY ETbtoEPIi18Wb1UF47//hrZgwuZRZGlVvQAh2fc= X-Google-Smtp-Source: ABdhPJwjG2Eik5aT6OflalaIOxUmKebKLMArWWJIr9yHJF2ChA0/W1hiLnZNXXttSGnr95LgXclP6G9pknKSCjt7pMo= X-Received: by 2002:a05:6000:156d:: with SMTP id 13mr5311989wrz.33.1642105487950; Thu, 13 Jan 2022 12:24:47 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Csaba Raduly Date: Thu, 13 Jan 2022 21:24:36 +0100 Message-ID: Subject: Re: -Wsign-conversion flag in gcc in cygwin. To: Amit X-Spam-Status: No, score=-0.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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 List-Archive: List-Post: List-Help: List-Subscribe: , Cc: cygwin list Content-Type: text/plain; charset="utf-8" Sender: "Cygwin" Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by delorie.com id 20DKP8TG004755 On Thu, 13 Jan 2022 at 15:34, Amit wrote: > > Hi, > > When I compile "long x = strlen("abcde")" on a linux system with the > following gcc flags -Wall -Wconversion, I get the following warning: ... > warning: conversion to ‘long int’ from ‘size_t’ may change the sign of the result [-Wsign-conversion] Which Linux system? I get the same result on Ubuntu (WSL) $ cat conversion-warning.c #include int main() { long x = strlen("meow"); // compile with -Wall -Wconversion return x; } $ gcc-10 -Wall -Wconversion conversion-warning.c conversion-warning.c: In function ‘main’: conversion-warning.c:6:12: warning: conversion from ‘long int’ to ‘int’ may change value [-Wconversion] 6 | return x; | ^ (Note, this is not the sign conversion from size_t to (signed) long, but the truncation from long to int) $ gcc-10 --version gcc-10 (Ubuntu 10.3.0-1ubuntu1~20.04) 10.3.0 Copyright (C) 2020 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ gcc-10 -dumpmachine x86_64-linux-gnu Csaba -- You can get very substantial performance improvements by not doing the right thing. - Scott Meyers, An Effective C++11/14 Sampler So if you're looking for a completely portable, 100% standards-conformant way to get the wrong information: this is what you want. - Scott Meyers (C++TDaWYK) -- 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