Comma operator = broken design

Robert Jacques sandford at jhu.edu
Thu Dec 8 17:19:34 PST 2011


On Thu, 08 Dec 2011 13:17:44 -0500, so <so at so.so> wrote:

> On Thu, 08 Dec 2011 19:25:10 +0200, Dejan Lekic <dejan.lekic at gmail.com>
> wrote:
>
>>>
>>> type a = a + 2; // compiles with no errors, no warnings, no explosions
>>> (that i know of)
>>
>> If "type" has the default initialiser, then what is the problem?
>
> What does it do in both C and D context?
> 1. It does different things.
> 2. C version even worse because of debug/release difference.
> 3. If D still does this, it violates the B-D rule (either does the same
> thing or doesn't compile at all. Actually there are many things violate
> this rule...)
>
> type a; // even this simple code violates B-D rule.
>
> What is the use case?
> . Is there any?
> . If there is not any you think, but still compiler allows it, it
> generates nothing but bugs (from experience :) ).
>
> Question should be, why does it exist at all?

Actually, these statements don't violate the B-D rule. In C/C++ the value of 'a' prior to use is implementation defined (i.e. it is undefined by the spec) and in practice tends to be some random stack value. D just sets that value to a consistent default, which is completely compliant with the C spec.


More information about the Digitalmars-d mailing list