B
BartC
Ben Bacarisse said:Why are there structs here at all? I think that's the point that's been
made elsewhere ("be dumb, not smart") and what I was getting at by
saying that it looks more like a translator than a compiler.
That's been considered! And for both arrays and structs. But there were some
downsides:
Where arrays are well-behaved and there is obviously an indexing operation,
then I do use C's object-sized offsets. The alternative would be to
incorporate a multiply operation within the address calculation. In
assembler, this often just means a zero-cost scale factor on a register. In
C the operation would need to be explicit. Probably this isn't important,
the compiler will optimise it out, but it looks poor.
But the main problems were that initialising a complex struct or array (or
some combination) meant serialising the contents into a sequence of byte
values. That would include floating point constants, and knowing byte-order
of integers etc.
Even in assembler, you can define byte, word, double word and floating point
constants! C would become *too* low-level then.
Besides, doing this for addresses of objects would be impossible, or for
initialisation of auto structs or arrays which involve runtime expressions
(although the latter is probably an extension of gcc and I can take care of
it myself if necessary).
In fact I'd also considered encapsulating all arrays within a struct, then
names of arrays would behave like other variables (by value).
But another reason, is that the resulting code already looks like a travesty
of the C language; eliminating half the data types would make it worse. If
you say it's acceptable however, then I will think again, but it needs to be
workable (because of the serialising issues).
I suspect that you want the benefit of some C typing (so you don't have
Using C's type system for primitives is still necessary, otherwise it would
be impossible to write expressions. Given a "+" operator, C needs to know
what the types of the operands are. In assembler, this information is
provided in other ways.