More D newb questions.
Walter Bright
newshound1 at digitalmars.com
Mon May 5 12:07:55 PDT 2008
Me Here wrote:
> I getting error message from the following code that I do not know how to
> interpret.
When this happens, the best way to find out what is wrong is to make a
copy of your code in test.d, then ruthlessly whittle down your code
until you get the minimum that produces the error. Then, usually, what's
causing the error becomes obvious.
In your particular case, the code is trying to concatenate characters,
not arrays of characters. There is no language support for concatenating
individual char values.
As for the int conversions, that is following standard C integral
promotion rules. Lots of people argue that those rules don't make much
sense today, but the consequence of changing them is to make it very
difficult to transliterate C code to D code without subtly breaking things.
> Why does D think I'm trying to concatenate ints, when teh only expressions
> involving catenation are
> slices of char[] abcd?
abcd[x] is not a slice, it is a char value. Per the C integral promotion
rules, the char is then promoted to int. A slice would be abcd[x..x+1].
> Why is D casting my carefully specified ushorts to ints when doing
> bit-twiddling?
The C integral promotion rules.
> Finally, is it possible to populate a static lookup table at runtime?
What you're looking for is array content assignment, which is done in D
with:
table[x][] = abcd[];
which will copy the contents of the array from abcd to table[x].
More information about the Digitalmars-d
mailing list