public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Csaba Raduly <rcsaba@gmail.com>
To: Amit <amitchoudhary0523@gmail.com>
Cc: cygwin list <cygwin@cygwin.com>
Subject: Re: -Wsign-conversion flag in gcc in cygwin.
Date: Thu, 13 Jan 2022 21:24:36 +0100	[thread overview]
Message-ID: <CAEhDDbDtz7E3YeBENmY3kvhHBoSw8Mtum_xC-3=sP0=ZYGmF=Q@mail.gmail.com> (raw)
In-Reply-To: <CAFf+5ziAh0X9cujnRMiSS0bcZWoZX7wi4aaAb2n1k0rLDf=3xQ@mail.gmail.com>

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 <string.h>

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)

      reply	other threads:[~2022-01-13 20:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-13 14:33 Amit
2022-01-13 20:24 ` Csaba Raduly [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAEhDDbDtz7E3YeBENmY3kvhHBoSw8Mtum_xC-3=sP0=ZYGmF=Q@mail.gmail.com' \
    --to=rcsaba@gmail.com \
    --cc=amitchoudhary0523@gmail.com \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).