See "The C Programming Language", 2nd edition, by Kernighan and Ritchie,
pages 149-150.
--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Inside a structure or union, it represents an unsigned integral
bitfield that occupies 6 bits;
Outside a structure or union, it represents a syntax error.
Have fun.
>
Inside a structure or union, it represents an unsigned integral
bitfield that occupies 6 bits;
Perhaps the OP will wonder why such a thing could be useful.
A couple of common examples where bitfields are used are device drivers,
because combinations of flags (i.e. bits) are often stored in a single
byte in hardware; and binary data formats, which frequently contain
fields that aren't aligned at byte boundaries. Whether you realize it or
not, you're relying on bitfields every time you send an IP packet!
Here's the IP header struct that's used in every packet:
>Almost assuredly, OP is not using a fancy apple or sun machine, true.
>(That code most certainly needs gcc or gcc-compatible compiler,
>but that's something almost assuredly used by OP, indirectly)
>
The structure as presented would have *not* been correct on almost any
x86 implementation (actually on none that I know of, and I frankly
doubt there are any where it would have been).
Of course it's quite likely that the OP is using an x86, but it's not
the absolute certainty you're implying. I think the latest stats are
that 20% of laptop sales are Apples, and I imagine that C programmers
are disproportionat ely likely to be using interesting big-endian
hardware for their work...
On Apr 15, 2:49 am, Antoninus Twink <nos...@nospam. invalidwrote:
On 15 Apr 2008 at 2:04, robertwess...@y ahoo.com wrote:
>
On Apr 14, 5:20 pm, ymunt...@gmail. com wrote:
Almost assuredly, OP is not using a fancy apple or sun machine, true.
(That code most certainly needs gcc or gcc-compatible compiler,
but that's something almost assuredly used by OP, indirectly)
>
The structure as presented would have *not* been correct on almost any
x86 implementation (actually on none that I know of, and I frankly
doubt there are any where it would have been).
>
Of course it's quite likely that the OP is using an x86, but it's not
the absolute certainty you're implying. I think the latest stats are
that 20% of laptop sales are Apples,
All of which are now x86. (Actually it's probable that Apple is still
moving a handful of PPC based systems to people who care more about
compatibility than price or performance).
and I imagine that C programmers
are disproportionat ely likely to be using interesting big-endian
hardware for their work...
All of which are now x86. (Actually it's probable that Apple is still
moving a handful of PPC based systems to people who care more about
compatibility than price or performance).
True, but mostly as embedded gear. There are darn few primary
computing* systems that aren't x86 out there (and even fewer shipping
now), older PPC based Macs are probably the biggest population.
*Desktops, laptops, servers, HPC systems - IOW, non-embedded stuff
On Thu, 17 Apr 2008 00:09:40 -0400, CBFalconer wrote:
Anand Hariharan wrote:
>Kaz Kylheku wrote:
>>saverio.p...@ gmail.com wrote:
>>>
>>>What does this represent?
>>>>
>>> unsigned int n : 6;
>>>
>>Your pitiful inability to consult a reference manual.
>>
>Given a "reference manual", where would you look it up?
>
Under "Declaratio ns".
>
Looking up K&R2 index entry for "declaratio n", I see page references 9, 40
and 210-218.
Pages 9 and 40 do not discuss bit fields. Pages 210-218 gets into grammar,
and does not get into bit fields until mid-way of page 212. Not the
easiest of pages in this book to find the answer I sought out to find.
There are a dozen odd more entries for declaration, but nothing that says
"declaratio n, with colon" or something similar.
The entry for "declaratio n, structure" takes one to either page 128 or
212. Bit fields are covered in the same chapter as page 128, but it does
not come until page 150.
The index itself begins with entries for symbols starting from '0' to ...
'\0' (the quotes are mine), but no entry for ':'.
This isn't a critique of K&R2's index, but just to point out that it is
not obvious where to find an answer to OP's question. Considering that one
could always mouth off a rebuttal based on "reference manual" and
"consult", I suppose I am wasting my time ....
What does this represent?
>
unsigned int n : 6;
>
???
As shown this is a syntax error. Within a structure or union
declaration, this declares 'n' to be a "bit field" of 6 bits width and
of type unsigned int.
Comment