From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2513 invoked by alias); 19 Feb 2003 12:25:48 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 2502 invoked from network); 19 Feb 2003 12:25:47 -0000 Received: from unknown (HELO garibaldi.home) (62.30.75.143) by 172.16.49.205 with SMTP; 19 Feb 2003 12:25:47 -0000 Received: from codesourcery.com (localhost.localdomain [127.0.0.1]) by garibaldi.home (8.12.5/8.12.5) with ESMTP id h1JCPfEA001730; Wed, 19 Feb 2003 12:25:42 GMT Message-ID: <3E5377C5.30208@codesourcery.com> Date: Wed, 19 Feb 2003 12:25:00 -0000 From: Nathan Sidwell Organization: Codesourcery LLC User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.1) Gecko/20021003 X-Accept-Language: en-us, en MIME-Version: 1.0 To: ccroswhite@get2chip.com CC: gcc-help@gcc.gnu.org Subject: Re: c++, gcc3.2.2 and bitwise operations References: <43834.64.169.83.2.1045618399.squirrel@webmail01.get2chip.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2003-02/txt/msg00170.txt.bz2 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