Opaque structs
Maxim Fomin
maxim at maxim-fomin.ru
Sat Jun 29 01:54:32 PDT 2013
On Saturday, 29 June 2013 at 08:01:17 UTC, Johannes Pfau wrote:
> Am Fri, 28 Jun 2013 22:16:33 +0200
> schrieb Andrej Mitrovic <andrej.mitrovich at gmail.com>:
>
>> On 6/28/13, Johannes Pfau <nospam at example.com> wrote:
>> > A naive question: Why isn't struct S {} enough? This should
>> > be a
>> > struct with size 0 so why do we need to disable the
>> > constructor and
>> > postblit explicitly?
>>
>> Because the user should never be able to use such a struct by
>> value,
>> in other words a user might mistakenly write code such as:
>>
>> S s2 = *s; // copies 1 byte
>
> But why is that legal / does that copy _one_ byte? It seems
> like that's
> totally arbitrary. Shouldn't doing anything value-related on
> an empty struct be invalid anyway?
It copies one byte because empty structs have one byte -
according to D implementation. The value can be adjusted using
align() atrribute.
More information about the Digitalmars-d-learn
mailing list