From: Vikram T. <vik...@ya...> - 2005-08-07 10:30:52
|
Hi, I wan't to read 8 bits and then return the combined output of all those 8 bits. so I need to define a char and 8 bits in a Unoin.. how do I do that, as it is giving error..... Thanking u in anticipation.. --Vikram ____________________________________________________ Start your day with Yahoo! - make it your home page http://www.yahoo.com/r/hs |
From: Peter O. <Pet...@bt...> - 2005-08-07 10:36:46
|
On Sun, 2005-08-07 at 03:29 -0700, Vikram Tamboli wrote: > Hi, > > I wan't to read 8 bits and then return the combined > output of all those 8 bits. Combined in what way ? > so I need to define a char > and 8 bits in a Unoin.. how do I do that, as it is > giving error..... Please post you code that is giving the error. Peter |
From: Vikram T. <vik...@ya...> - 2005-08-08 15:35:02
|
Hi, union { char controlword; bit controlword_0; bit controlword_1; bit controlword_2; bit controlword_3; bit controlword_4; bit controlword_5; bit controlword_6; bit controlword_7; }cw; this is what I was doing and it was giving me error as storage class not allowed here After replacing the above code with the below(as suggested by Mr.Raphael) the errors were gone typedef union { struct { unsigned char bit0:1; unsigned char bit1:1; unsigned char bit2:1; unsigned char bit3:1; unsigned char bit4:1; unsigned char bit5:1; unsigned char bit6:1; unsigned char bit7:1; }; /* anonymous struct, can be named like "} bits;" */ unsigned char raw; } my_complex_type_t; my_complex_type_t my_var; Access your data bitwise via "my_var.bit0 = 1;" or bytewise via "my_var.raw = 0x34;" But can any one explain where I was wrong or why didnt my code worked. Regards Vikram --- Peter Onion <Pet...@bt...> wrote: > On Sun, 2005-08-07 at 03:29 -0700, Vikram Tamboli > wrote: > > Hi, > > > > I wan't to read 8 bits and then return the > combined > > output of all those 8 bits. > > Combined in what way ? > > > so I need to define a char > > and 8 bits in a Unoin.. how do I do that, as it > is > > giving error..... > > Please post you code that is giving the error. > > Peter > > > > ------------------------------------------------------- > SF.Net email is Sponsored by the Better Software > Conference & EXPO > September 19-22, 2005 * San Francisco, CA * > Development Lifecycle Practices > Agile & Plan-Driven Development * Managing Projects > & Teams * Testing & QA > Security * Process Improvement & Measurement * > http://www.sqe.com/bsce5sf > _______________________________________________ > Sdcc-user mailing list > Sdc...@li... > https://lists.sourceforge.net/lists/listinfo/sdcc-user > __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com |
From: Ken J. <Ken...@ie...> - 2005-08-08 16:20:19
|
Since cw is a union, all those bits were occupying the same bit. Personally, I don't like either approach. I find it much better to use bitwise operators. e.g.: unsigned char cw; if (some test) cw |= BITMASK(1); if (some other test) cw &= 0xFC; etc. -Ken Jackson Vikram Tamboli writes: > Hi, > > union > { > char controlword; > bit controlword_0; > bit controlword_1; > bit controlword_2; > bit controlword_3; > bit controlword_4; > bit controlword_5; > bit controlword_6; > bit controlword_7; > }cw; > > this is what I was doing and it was giving me error as > storage class not allowed here > ... > But can any one explain where I was wrong or why didnt > my code worked. > > Regards > > Vikram |
From: Erik P. <epe...@iv...> - 2005-08-08 16:47:07
|
On Mon, 8 Aug 2005, Vikram Tamboli wrote: > union > { > char controlword; > bit controlword_0; > bit controlword_1; > bit controlword_2; > bit controlword_3; > bit controlword_4; > bit controlword_5; > bit controlword_6; > bit controlword_7; > }cw; > > this is what I was doing and it was giving me error as > storage class not allowed here "bit" is not only a data type but also a storage class, like "data" and "xdata". It specifies a boolean data type that resides in the bit-addressable memory space. Since all of the fields of a struct or union need to be in the same memory space (and hence have the same storage class), it is not permitted to specify a storage class for the fields individually. Erik |
From: Raphael N. <RN...@we...> - 2005-08-07 11:42:44
|
Hi Vikram, > I wan't to read 8 bits and then return the combined > output of all those 8 bits. so I need to define a char > and 8 bits in a Unoin.. how do I do that, as it is > giving error..... Perhaps you need: typedef union { struct { unsigned char bit0:1; unsigned char bit1:1; unsigned char bit2:1; unsigned char bit3:1; unsigned char bit4:1; unsigned char bit5:1; unsigned char bit6:1; unsigned char bit7:1; }; /* anonymous struct, can be named like "} bits;" */ unsigned char raw; } my_complex_type_t; my_complex_type_t my_var; Access your data bitwise via "my_var.bit0 = 1;" or bytewise via "my_var.raw = 0x34;" Raphael |