---------------------------------------- > 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.. >>> """ >>> >>> >> >> Platform specific- INT_MAX doesn't have to be 011111....1111. It can be >> all 0's, if the platform is braindead. So that's undecidable without more >> knowledge. >> > In general, with bitwise operators, you need to be sure about the > bitwise layout of your types. It does seem odd to use INT_MAX instead of > (~0) for a mask, but who knows what the intent is. >> This is a case where you'd have to cast one or the other's values to change >> the sign. Usually you cast the signed to unsigned, but that's a style >> thing. Most compilers take an explicit cast to be always correct, and won't >> generate a warning. >> > Really, the above logic seems odd, but it is really hard to know what is > wrong or right about it without more information. It certainly seems > like an odd bit of code. > 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.
Gabe _________________________________________________________________ Test your Star IQ http://club.live.com/red_carpet_reveal.aspx?icid=redcarpet_HMTAGMAR -- [email protected] http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg
