TDPL error(s)

Timon Gehr timon.gehr at gmx.ch
Sun May 8 08:11:46 PDT 2011


> On Sun, 08 May 2011 17:59:02 +0400, Timon Gehr <timon.gehr at gmx.ch> wrote:
>
>> On page 263, TDPL states that struct objects nested inside a function
>> cannot
>> be returned, because the caller does not have access to their types.
>> Using the
>> auto keyword, DMD lets you do this though. Is this a bug in DMD or an
>> error in
>> TDPL?
>>
>
> I think that's fine.

Being fine is not an option. They contradict each other.

>
>
> Without looking at the code, I'd assume that Local is defined something
> like this:
>
> struct Local
> {
>  size_t s;
>  int i;
> }
>
> in which case Local.sizeof would most likely be size_t.sizeof * 2 because
> of the alignment and implicit padding, i.e 8 bytes on x86, and 16 bytes on
> x64. size_t.sizeof + int.sizeof only give 12.
>
> I'd agree that this is in fact confusing and needs to be explained.

I see. After further reading, the alignment of structs is indeed explained.


More information about the Digitalmars-d mailing list