piclist 2005\08\19\085459a >
Thread: Re: I say it is spinach . . .
picon face BY : Gerhard Fiedler email (remove spam text)

Peter wrote:

>>> struct _packed_bits {
>>>                   unsigned int bit0:1;
>>>                   unsigned int bit1:1;
>>> } packed_bits;
>> Now try to get the address of bit0, or to pass it to a function.
> That is a pointer question ;-) You can pass only a pointer to modifiable
> data as an argument to a function.

Bitfields /are/ modifiable data. It's just not possible to get the address
of a bitfield (whereas that works with other members of structs). In that
sense, bitfields are not fully integrated into the language.

> Therefore the limitation is that in C the *pointer* to the smallest
> entity is a pointer to an int (maybe to a char). No ?

It's a pointer to char (and the size of a C char is an implementation thing
-- it's not defined in the language, even though in most implementations it
is a byte). But there's no inherent reason why there couldn't be a type
"bit" with a pointer to it.

HiTech C (like many other "small processor C" implementations) has a type
"bit" -- it is a single bit, not surprisingly :) --, but no pointer to it.
I don't see a (language) reason why there couldn't be a pointer to a bit
type. They just would have to add some code to the compiler to properly
deal with this.

In terms of efficiency, it doesn't matter whether you use a
struct/bitfield, bitwise-or or the bit type to set a single bit -- all
three cases the result is a single bsf instruction.

BTW, it /is/ possible to create a substitute for a bit pointer, using a
struct that contains a pointer to a byte and a bit address, together with
some functions that then set/clear/test the bit identified by such a
pointer. You just can't use the standard C pointer (de)referencing
operators & and * (that would require C++'s operator overloading...)

<7077ixl9n05f$.1pmarov59b9hr$.dlg@40tude.net> 7bit

In reply to: <t.rxiuja@qgd.nbr.aa>
See also: www.piclist.com/techref/io/serial/spis.htm?key=spi
Reply You must be a member of the piclist mailing list (not only a www.piclist.com member) to post to the piclist. This form requires JavaScript and a browser/email client that can handle form mailto: posts.
Subject (change) Re: I say it is spinach . . .

month overview.

new search...