On Wed, 28 Apr 2004 23:01:59 +0200, Jacek Dziedzic
<jacek__NOSPAM__@janowo.net> wrote in comp.lang.c++:
[color=blue]
> Ron Natalie wrote:
>[color=green]
> > "Philipp" <nospam_kitschen@hotmail.com> wrote in message news:408fe268$1@epflnews.epfl.ch...
> >[color=darkred]
> >>Hello
> >>I'm working on a piece of code which I did not write and it has
> >>variables defined as:
> >>
> >> unsigned short i:13;
> >> unsigned short j:13;
> >> unsigned short k:3;
> >>
> >>As I understand the code, this means that i is reduced to being coded on
> >>13 bits (same for j) and k is reduced to 3 bits.
> >>1) Is my understanding right?
> >>2) Is there any documentation on this ":" operator somewhere (I could
> >>not find anything by searching the web)
> >>[/color]
> >
> >
> > Look up "bitfield" (or perhaps "bit field") in your C text.
> >
> > : here isn't an operator, it's part of the declaration syntax. Bitfields are a bit funky.
> > It is used to carve up an integral type into smaller pieces. The packing of the bits
> > into the larger type is extremely machine dependent.[/color]
>
> Whoa, what are these? I've never seen a thing like that before! :).
> Is this Standard C++, or C perhaps? Or a relic of some sorts like
> the auto keyword? My compiler gives a "declaration syntax error" for:
>
> // ---
> int main() {
> unsigned short k:13;
> }
> // ---
>
> Can anybody shed some light on this?[/color]
Bit-fields have been part of C for about 30 years now, before the
publication of the first edition of K&R. They have been part of C++
since its beginning.
But they cannot be used as stand-along objects, only as members of
structs and (in C++ only, of course) classes.
Any decent book on C or C++ should cover them.
--
Jack Klein
Home:
http://JK-Technology.Com
FAQs for
comp.lang.c
http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++
http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html