c++, gcc3.2.2 and bitwise operations

Nathan Sidwell nathan@codesourcery.com
Wed Feb 19 12:25:00 GMT 2003


Chris Croswhite wrote:
> How can I play with the guts of a variable one bit at a time in c++?  That
> is, I want to do something like this,
> 
> long long val =0x4000000000000001;
> ((int*)(&val)[1]) &= 0x0;
> 
> (this should set the first bit to zero).  This worked with gcc 2.95.x, but I
> understand now that the casting (&val)[1] (to an array) is "undefined" and
> therefore not predictible.
> 
> Could anyone give me hand?
a) read the documentation about type based aliasing
b) don't do that :)

nathan

-- 
Nathan Sidwell    ::   http://www.codesourcery.com   ::     CodeSourcery LLC
          The voices in my head said this was stupid too
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org




More information about the Gcc-help mailing list