Christopher Smith wrote:
> Gabriel Sechan wrote:
>> ----------------------------------------
>>
>>> Date: Mon, 31 Mar 2008 16:24:43 -0700
>>> From: [EMAIL PROTECTED]
>>> To: [email protected]
>>> Subject: Re: C++0X gets lambdas/closures
>>>
>>> Gabriel Sechan wrote:
>>>
>>>>> Would this be correct?
>>>>> """
>>>>> #include ...
>>>>> if (libretval_x & INT_MAX < mysigned_x)
>>>>> do something..
>>>>> """
>>>>>
>> Actually, signed vs unsigned is probably the most common warning out
>> there. Its due to a lot of APIs deciding to use unsigned if there's
>> no reason for something to be negative, and a lot of programmers just
>> using int if there's no reason not to.
>>
> It's still not clear if libretval_x is unsigned or signed, (or if
> mysigned_x is poorly named), so I'm not sure if this is really what is
> going on here. For all we know, libreval_x is a function pointer. ;-)
Ahh. The original question referred to a library function returning an
unsigned, and comparing that to an int -- at least, that's how I read it.
I guess my sample code might have given a warning, too? Perhaps it
should have been
if ((int)(libretval_x & INT_MAX) < mysigned_x)
The '& INT_MAX' was merely intended to be an in-code hint that the
conversion was known to be reasonable.
Perhaps it should even have been
"""
assert(libretval_x <= INT_MAX);
if (int)libretval_x < mysigned_x
do_something..
"""
or maybe
"""
inline
int u2i(unsigned u) { assert(u <= INT_MAX); return (int)u; }
if (u2i(libretval_x) < mysigned_x)
do_something..
"""
Now, perhaps this would be a good time to gripe about 'const'?
That probably gives more headaches than signed/unsigned warnings, no?
Regards,
..jim (feel free to fix my c .. it's been a while)
--
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg