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)

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

Reply via email to