help with c translation
Lars T. Kyllingstad
public at kyllingen.NOSPAMnet
Thu Jul 2 04:56:01 PDT 2009
Ary Borenszweig wrote:
> Lars T. Kyllingstad escribió:
>> robby wrote:
>>> i'm using D1/Tango. sorry, im not sure to how to explain the error
>>> messages, but if you need to look a t full code, here is the link
>>> http://www.ibsensoftware.com/download.html
>>>
>>> thanks again.
>>
>>
>> Several places in that code, I notice things like this:
>>
>> const type foo;
>> ...
>> foo = bar;
>>
>> I have no idea why this works in C, but in D it certainly doesn't.
>
> Well, it should work! const means, once a value is assigned to that
> variable, it never changes again. The compiler can do static analysis to
> verify this. And that's why it works. And that's why D should also work
> this way, IMHO.
I suppose it's linked to D's automatic initialization of variables. If I
understand it correctly, just typing
const int foo;
is the same as
const int foo = 0;
With your suggestion, const variables could not be automatically
initialized. In that case:
int* foo; // foo is null
const int* bar; // bar could point anywhere!
-Lars
More information about the Digitalmars-d-learn
mailing list