Michel Fortin escribió:
On 2009-03-06 14:35:59 -0500, Walter Bright <[email protected]> said:

Andrei Alexandrescu wrote:
"Can't live without bitfields! Give me bitfields and I'll lift the Earth!"

"Here they are, std.bitmanip. Well-defined and more portable and flexible than C's."

"Meh, don't like the definition syntax."

Classic.

Well, he certainly has a point. Compare this:

    mixin(bitfields!(
        uint, "x",    2,
        int,  "y",    3,
        uint, "z",    2,
        bool, "flag", 1));

With this:

    uint x : 2;
    int  y : 3;
    uint z : 2;
    bool flag : 1;

The second is certainly prettier and more readable.

Does it matter much? Not to me; I rarely use bit fields. If I were using them a lot, perhaps I'd be more concerned.

While I don't care very much about bitfields, that "mixin(tmpl!(...))" syntax is awful. "mixin tmpl!(...)" is better, but has too many limitations, and it isn't always clear for the user which one should be used. Couldn't D2 get a better syntax for mixins?

Well, now the \ is character if free:

\bitfields(
  unit, "x", 2,
  int, "y", 3,
  uint, "z", 2,
  bool, "flag", 1,
);

But I think it looks ugly: the \ is "lambda" in some languages and this also reminds me of LaTeX... :-P

Reply via email to