public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* -Wsign-conversion flag in gcc in cygwin.
@ 2022-01-13 14:33 Amit
  2022-01-13 20:24 ` Csaba Raduly
  0 siblings, 1 reply; 2+ messages in thread
From: Amit @ 2022-01-13 14:33 UTC (permalink / raw)
  To: cygwin

Hi,

When I compile "long x = strlen("abcde")" on a linux system with the
following gcc flags -Wall -Wconversion, I get the following warning:

==============================
size.c: In function ‘main’:
size.c:7:17: warning: conversion to ‘long int’ from ‘size_t’ may
change the sign of the result [-Wsign-conversion]
  long x = strlen("abcde");
                 ^
==============================

But on cygwin, I don't get this warning.

So, is -Wsign-conversion flag not implemented in gcc in cygwin?

--------------------------------------------------------------
$ gcc --version
gcc (GCC) 11.2.0
Copyright (C) 2021 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 -dumpmachine
x86_64-pc-cygwin
--------------------------------------------------------------

Amit

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: -Wsign-conversion flag in gcc in cygwin.
  2022-01-13 14:33 -Wsign-conversion flag in gcc in cygwin Amit
@ 2022-01-13 20:24 ` Csaba Raduly
  0 siblings, 0 replies; 2+ messages in thread
From: Csaba Raduly @ 2022-01-13 20:24 UTC (permalink / raw)
  To: Amit; +Cc: cygwin list

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)

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-01-13 20:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-13 14:33 -Wsign-conversion flag in gcc in cygwin Amit
2022-01-13 20:24 ` Csaba Raduly

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).