B
BartC
Shao Miller said:On 2/4/2013 20:17, BartC wrote:
Why do they have to be crude? Functions that the implementation provides
as extensions needn't be crude at all, and could translate with whatever
efficiency is possible.
A function library created with ordinary C with no implementation help will
always be lacking.
There is no overloading of the functions (so you'd need separate sets to
deal with 1-bit and 4-bit, unless you made the width a parameter, which is
unwieldy). No overloading of built-in operators (so you'd be writing
indexbit(a,i) instead of a). And so on. There's no integration with the
language.
And without being a standard language feature, every implementation will be
different.
bit s[256]; //32 bytes
bit* p = &s[123];
/* Is this allowed? */
struct {
int i;
bit ba[5];
double d;
} foo;
size_t sz = sizeof foo;
That's tricky, because C already has bit-fields inside structs! So I'm not
sure how they would interact, or whether successive odd-length bit-arrays
would be packed together, so the next one could start in the middle of a
byte.
(In my implementation, I don't have single bits as independent variables or
struct members; they're only allowed in arrays or as pointer targets (so
it's possible to point to the middle of an ordinary int for example). Your
ba[5] example would start on a byte boundary, and its size would be rounded
up to the next byte, ie. 1 byte.)