Re: [cc65] bit-fields

From: Groepaz <groepaz1gmx.net>
Date: 2009-08-30 13:40:12
On Sonntag 30 August 2009, silverdr@wfmh.org.pl wrote:
> On 2009-08-30, at 11:25, Ullrich von Bassewitz wrote:
> > Ok, the compiler can do bit-fields since yesterday. If anybody dares
> > to test
> > this feature, I would be glad about some feedback.
>
> Looks like you did it! The emitted code seems also relatively compact.
>
> One thing that cought my attention:
>
> #include <stdio.h>
>
> void main(void)
> {
> 	struct foo
> 	{
> 		unsigned int bar0 : 1;
> 		unsigned int bar1 : 1;
> 		unsigned int bar2 : 1;
> 		unsigned int bar3 : 1;
> 	};
>
> 	struct foo bars;
>
> 	bars.bar0 = 0;
> 	bars.bar1 = 1;
> 	bars.bar2 = 0;
> 	bars.bar3 = 0;
>
> 	printf("\nSize of int = %d", sizeof(int));
> 	printf("\nResult = %04X\n", bars);
> }
>
> Gives:
>
> Size of int = 2
> Result = 00F2
>
> Sure - I shouldn't bother much about the uninitialised part of the
> struct representation but am simply flagging that as it seems one byte
> is differently handled than the other - it makes me suspicious and
> possibly it might be worth checking for bugs there...

probably coincedence - the local variable will be located on the (software) 
stack, and (if not initialized) the initial value will be more or less random 
because of that.

-- 

http://www.hitmen-console.org    http://magicdisk.untergrund.net
http://www.pokefinder.org        http://ftp.pokefinder.org

Wenn eine vom Kopienräuber geraubte Kopie eine Raubkopie ist, dann ist ein vom 
Kopiererräuber geraubter Kopierer ein Raubkopierer.

----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Sun Aug 30 13:40:23 2009

This archive was generated by hypermail 2.1.8 : 2009-08-30 13:40:25 CEST