D Design Could Be Improved

Jarrett Billingsley kb3ctd2 at yahoo.com
Sun Dec 17 07:29:55 PST 2006


"Aleksey S. Skidan" <al.skidan at gmail.com> wrote in message 
news:em3mj6$2s7m$1 at digitaldaemon.com...
> The inline assembler seems to be a weak point in the language design.
> I do like the GCC inline assembler and can't understand the reasons
> why not to use it. The current implementation of D's inline assembler
> is IMNHO not good.
> Let's consider the following example:
> asm{ di 2+3; }
> The code won't ever be compiled. Just because the assembler consider 2+3 
> not
> to be a constant expression. But it certainly is (it depends on 2 
> constants).
> The other ugly thing is Intel syntax. There's a lot of software written in
> AT&T syntax. I guess both the Intel and AT&T syntaxes must be available.
> The weakness of current inline assembler makes the language (i mean D) not
> fitable for system programming.
> I noticed that there's no ability to name a symbol in a way like that:
> void foo() asm("bar"); Please, note that this kind of naming is very handy 
> for
> embeded systems and a lot of stuff like that. Yep, there's extern(C) but 
> why
> does it underscore? There must be a switch that turns underscoring off. 
> The
> next disappointment is that one can't specify where to put a symbol. I 
> mean
> one can't say to put "foo" into .some_section instead of .text section.
> I do agree with the point that bit fields are BAD things. But the bit 
> array
> you introduced isn't better. You must at least specify the way the bit 
> array
> is stored in the memory: is it BE LE or what. The next thing about them is
> that they don't really save the memory. I mean that the bit[8] blah; is 32
> bits long. But then the better way to write the same thing is: enum{ B0, 
> B1,
> ..., B7 }; char blah;
>
> My best regards, Aleksey.

bit has not been a datatype in D for quite some time now.  If you're looking 
for a way to make "bitfields", a kind of cheap and easy way to do it is to 
write the appropriate struct in a C header:

typedef struct
{
    unsigned char a : 2;
    unsigned char b : 2;
    unsigned char c : 4;
} Foo;

Then run it through htod.  This will generate a D struct with built in 
setters and getters for the "bitfields", which is really exactly what C does 
for you under the hood.  Using optimization and inlining, those setters and 
getters will probably disappear. 





More information about the Digitalmars-d mailing list