November 15, 2004 Re: D shouldn't be different from Java without good reason | ||||
---|---|---|---|---|
| ||||
Posted in reply to Anders F Björklund | "Anders F Björklund" <afb@algonet.se> wrote in message news:cnavkn$e0i$1@digitaldaemon.com... > Ben Hinkle wrote: > > > A few of the posts listed on that page are about bool/bit not begin addressable. That got me thinking about adding (either builtin or through > > aliases or typedefs or something) a separate type for addressable bools/bits called ... drum roll please... wbit and wbool (naturally wbool > > is an alias for wbit). It would have the size of a byte (hence the "w") and > > otherwise behave like bit (which pretty much makes it behave like C++'s bool). Making bit addressable would mess up the rule that pointers all have > > the same size and are convertable to void* and back. > > You can take the address of bit variables now, > and they should also work as "out" parameters. > > You can't take the address of bits within arrays. > (or actually you can, but the pointer doesn't work) > > > A single bit field/var occupies a byte in memory, > and a bit[] field occupies (length+31)/32 bits. > > So "bit a; bit b;" is 2 bytes, "bit c[2];" is 4. > (the multiple of four is for access-speed reasons) I was being too vague. You are right that bits by themselves are addressable and can be used as out parameters. It's only when they get packed that life gets interesting - for better or worse. > --anders > > PS. > In the Mac OS X C++ compiler (g++) a "bool" is 4 bytes. > A "_Bool", as used in C99, also occupies a full four. > (that is, both have the same size as an "int" does...) > On Linux, they seems to have a usual sizeof() 1 byte ? Interesting. I hadn't really thought that bools can have different sizes but I suppose there isn't anything stopping it. Maybe int is better than byte. Dare I suggest "dbit" and "dbool" for int sized bits and bools? :-) |
November 15, 2004 Re: D shouldn't be different from Java without good reason | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ben Hinkle | Ben Hinkle wrote:
> Interesting. I hadn't really thought that bools can have different sizes but
> I suppose there isn't anything stopping it. Maybe int is better than byte.
> Dare I suggest "dbit" and "dbool" for int sized bits and bools? :-)
Enough! Enough! (my poor stomach) :-D
Hat's off for that most excellent suggestion!
Henceforth, byte/char shall be known as a "wbit" when used as a bool
and int/long shall similarly be known as a "dbit" when used as a bool.
Thus, one can choose between bit, wbit and dbit for storing booleans.
This makes it consistent with the other missing type, namely strings.
Oh, the humanity
--anders
|
November 15, 2004 Re: D shouldn't be different from Java without good reason | ||||
---|---|---|---|---|
| ||||
Posted in reply to Anders F Björklund | "Anders F Björklund" <afb@algonet.se> wrote in message news:cnb2jm$ic4$1@digitaldaemon.com... > Ben Hinkle wrote: > > > Interesting. I hadn't really thought that bools can have different sizes but > > I suppose there isn't anything stopping it. Maybe int is better than byte. > > Dare I suggest "dbit" and "dbool" for int sized bits and bools? :-) > > Enough! Enough! (my poor stomach) :-D > > Hat's off for that most excellent suggestion! > > > Henceforth, byte/char shall be known as a "wbit" when used as a bool and int/long shall similarly be known as a "dbit" when used as a bool. > > Thus, one can choose between bit, wbit and dbit for storing booleans. This makes it consistent with the other missing type, namely strings. > > > Oh, the humanity > --anders Actually I was being semi-serious! It is kindof overkill but I think explicit types with different behaviors are preferable to hacking up pointers. |
Copyright © 1999-2021 by the D Language Foundation