bug-gplusplus
[Top][All Lists]
Advanced

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

Re: its a bug - right


From: roger
Subject: Re: its a bug - right
Date: Wed, 06 Jun 2001 18:43:51 GMT
User-agent: Xnews/M3

address@hidden (Greg Chicares) wrote in
>
>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

Can you explain why -1 has to be converted to unsigned?

It seems reasonable that both sides of the conditional
should be expected to yeild the same type, and further, that
this should match (or be assignable to) the type of the 
lvalue being assigned, which in this case is an int, 
not an unsigned int.


Are the rules different for C++ vs C in this regard?
If not why doesn't gcc give the same warning?
The sun C++ compiler doesn't warn about this construct either.


If anything, it seems to me that  the compiler should warn 
that the potential unsigned result of the strlen 
term does not match the type to which it is being assigned.
But it doesn't.  Nor does it warn if say
   int x = strlen(foo);
so maybe I'm way off base on all of this...


Thanks.





reply via email to

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