On Fri, Sep 07, 2007 at 07:03:24PM +0000, Walter Bright wrote:=20 =20 Well htod does that, but it's very impractical to write them from scratch. Especially if you want to benefit from the fact that padding and integer sizes are very well defined to map e.g. structs onto a raw stream, avoiding deserialization and so on. And for that bit-fields are a really really fast and simple way to describe things. I mean, take your classical example of the foreach loop. Your whole point is that it's way shorter, and safer. And now you are saying that people should instead of sth like: struct my_struct { unsigned some_field : 2; unsigned has_this_property : 1; unsigned is_in_this_state : 1; unsigned priority_level : 2; ... } people should write (IIRC it works since ->some_field =3D 2 calls ->some_field(2) if the member does not exists, or maybe it's set_some_field, it's not very relevant anyway): struct my_struct { unsigned some_field() { return this->real_field >> 30; } void some_field(unsigned value) { this->real_field |=3D (value & 3) << 30; } ... private: unsigned real_field; } Please it has to be a joke: there is 42 ways for people to write it wrong (wrong shifts, wrong masks, and so on), it's horribly obfuscated, hence needs a lot of comments, whereas the bitfield is 90% self documented, and the syntax is _very_ clear, you cannot beat that. I would be absolutely fine with it being syntactical sugar for some kind of template call though. Not to mention that the usual C idiom: union { unsigned flags; struct { // many bitfields }; }; Would need an explicit copy_flags(const my_struct foo) function to work. Not pretty, not straightforward. Really, I feel this is a big lack, for a language that aims at simplicity, conciseness _and_ correctness. OK, maybe I'm biased, I work with networks protocols all day long, so I often need bitfields, but still, a lot of people deal with network protocols, it's not a niche. Last time I checked it was only available on windows, and closed source, both are an impediment for many people. It's definitely clear that gcc being opensource and available on so many platforms helped to make C what it is today. Lacking portable and free (as in speech) tools are an impediment to the succes of a language. Right now, for D, only gdc exists, it lags behind dmd quite a lot afaict, and there is no other toolchain helpers yet. Yeah I'm fine with that, but sadly it's not available everywhere like I said. =20 =20 =20 I completely agree, and I knew about Tango, and anyways, I'm so used to C, and D has so few to bring to my code style when I deal with low level system functions, that I'm totally fine with std.c.* anyways :) For the record I wasn't suggesting to rewrite git in D at all. I just happened to see your post, and being very interested in where D is going because I feel it's an excellent langage, and saw an opportunity to mention a few quirks I feel it has, so, well, I answered :) --=20 =C2=B7O=C2=B7 Pierre Habouzit =C2=B7=C2=B7O madcoder@debia= n.org OOO http://www.madism.org
| Greg KH | [GIT PATCH] driver core patches against 2.6.24 |
| david | Re: Dual-Licensing Linux Kernel with GPL V2 and GPL V3 |
| Rob Landley | What still uses the block layer? |
git: | |
| Antonio Almeida | HTB accuracy for high speed |
| Alexey Dobriyan | Re: [GIT]: Networking |
| Jarek Poplawski | [PATCH] pkt_sched: Destroy gen estimators under rtnl_lock(). |
| Gerrit Renker | [PATCH 27/37] dccp: Integration of dynamic feature activation - part 2 (server side) |
