From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20794 invoked by alias); 11 Dec 2012 17:04:59 -0000 Received: (qmail 20767 invoked by uid 22791); 11 Dec 2012 17:04:55 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00,KHOP_THREADED,RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail.agmk.net (HELO mail.agmk.net) (91.192.224.71) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 11 Dec 2012 17:04:47 +0000 Received: from localhost.localnet (unknown [84.10.194.214]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: pluto@agmk.net) by mail.agmk.net (Postfix) with ESMTPSA id 83FC586E75B; Tue, 11 Dec 2012 18:04:44 +0100 (CET) From: =?utf-8?B?UGF3ZcWC?= Sikora To: gcc-help@gcc.gnu.org, its.dipanjan.das@gmail.com Cc: Gert Hulselmans Subject: Re: Bit field ordering on Big-Endian (SPARC) processor Date: Tue, 11 Dec 2012 17:04:00 -0000 Message-ID: <1424496.6y8fhTSIjP@localhost> User-Agent: KMail/4.9.4 (Linux/3.7.0-rc8-00037-g1b3c393; KDE/4.9.4; x86_64; ; ) In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2012-12/txt/msg00037.txt.bz2 On Tuesday 11 of December 2012 18:31:06 Dipanjan Das wrote: > Consider the code below: >=20 > #define FORCE_CAST(var, type) *(type*)&var ^^^^^^^^^^^^^^^^ don't forget to use -fno-strict-aliasing with such ugly tr= icks. > struct processor_status_register > { > unsigned int cwp:5; > unsigned int et:1; > unsigned int ps:1; > unsigned int s:1; > unsigned int pil:4; > unsigned int ef:1; > unsigned int ec:1; > unsigned int reserved:6; >=20 > unsigned int c:1; > unsigned int v:1; > unsigned int z:1; > unsigned int n:1; >=20 > unsigned int ver:4; > unsigned int impl:4; > }__attribute__ ((__packed__)); iirc, the C language gives no guarantee of the ordering of fields within ma= chine words, so if you use them for the h/w register modeling, you program will not only= be nonportable, it will be compiler-dependent too. you should really read suitable byte/wor= d/doubleword from mapped h/w memory, convert it with le/be_to_cpu() method and shift/mas= k to access bits. BR, Pawe=C5=82.