Performance improvements for D / DMD compiler.
Kyle Furlong
kylefurlong at gmail.com
Sat Jan 20 01:36:44 PST 2007
Bill Baxter wrote:
> Walter Bright wrote:
>> Bill Baxter wrote:
>>> The question is how can we write functions in D that take big structs
>>> as parameters in such a way that it is:
>>> A) efficient and
>>> B) guaranteed not to change the caller's value
>>>
>>> In C++ the answer is const LargeStruct&.
>>
>> C++ doesn't *guarantee* it won't change. There are at least two legal
>> ways to do it.
>
> Very true. What I'm after is really a concise way to both
> a) document to readers of the code that it won't change and
> b) get the compiler to zap me if I accidentally try to modify it.
>
>>> In D the answer is...
>>
>> There aren't const references in D. But the 3 ways to pass it by
>> pointer are:
>>
>> 1) inout
>> 2) take the address and use a pointer
>> 3) make it a class instead
>
> And none of those accomplishes a or b.
>
> --bb
Ah the great const debate. I have a feeling that this discussion will be
a major part of D 2.0.
More information about the Digitalmars-d
mailing list