Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Re: ****ft oper...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 7 Topic 9493 of 10096
Post > Topic >>

Re: ****ft operator undefined behavior

by Olivier Langlois <olanglois@[EMAIL PROTECTED] > Apr 13, 2008 at 12:43 AM

{ Please note that top-posting is discouraged in this group. -mod }

Thank you Jack for the tip.

The other workaround that I have found to work on my platform is to
write:

unsigned char m = 32;
register unsigned mask = (static_cast<unsigned long long>(1)<<m)-1;

There is minor clarification I can add to what you wrote. If I am not
wrong, sizeof is a C++ reserved keyword and a builtin operator. Hence,
there should not be any header file defining sizeof.

Greetings,
Olivier Langlois
http://www.olivierlanglois.net
http://blog.olivierlanglois.net

> Example, almost but not universally ****table:
>
> #include <climits>
> /* include at least one header that defines std::sizeof */
>
> unsigned int safe_uint_****ft(unsigned int value, unsigned int bits)
> {
>     if (bits > (CHAR_BIT * std::sizeof(unsigned int)) return 0;
>     else return value << bits;
>
> }
>
> Put it in a header and make it inline if you like.
>
> That is essentially what you are asking he compiler to do for you, but
> many other programs don't want or need the extra check.


-- 
      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 7 Posts in Topic:
shift operator undefined behavior
Olivier Langlois <olan  2008-04-11 15:33:41 
Re: shift operator undefined behavior
Jack Klein <jackklein@  2008-04-12 12:13:12 
Re: shift operator undefined behavior
"Bo Persson" &l  2008-04-13 00:43:14 
Re: shift operator undefined behavior
Olivier Langlois <olan  2008-04-13 00:43:12 
Re: shift operator undefined behavior
=?ISO-8859-1?Q?Daniel_Kr=  2008-04-13 00:43:11 
Re: shift operator undefined behavior
Jack Klein <jackklein@  2008-04-14 10:43:12 
Re: shift operator undefined behavior
Greg Herlihy <greghe@[  2008-04-14 13:13:15 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Oct 14 8:29:37 CDT 2008.