bug-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: its a bug - right


From: Greg Chicares
Subject: Re: its a bug - right
Date: Wed, 06 Jun 2001 00:23:24 -0400

roger wrote:
> 
> Using g++ vesrion 2.95.3 on sun sparc solaris 7...
> 
> Here's a function:
>    int func (char *buf, int bufsize)
>    {
>        int i = bufsize ? -1 : bufsize - (int)strlen(buf);
>        int j = bufsize ? -1 : bufsize -      strlen(buf);
>    }
> 
> Now, what I see is the error:
>    "warning: converting of negative value '-1' to 'unsigned int'
> for the second line only - the one where I don't cast the strlen.
> 
> It looks like since strlen returns an unsigned int, g++ wants
> both sides of the conditional to be unsigned int, or something like that.
> Bug, right?

What behavior do you expect? I think it's like this:
  strlen returns size_t, an unsigned int
  so bufsize (an int) plus strlen is unsigned
  so -1 has to be converted to unsigned
  and that's a surprise in many cases, so you get a warning



reply via email to

[Prev in Thread] Current Thread [Next in Thread]