Struct literals limitation

JN 666total at wp.pl
Tue Nov 17 20:12:25 UTC 2020


On Monday, 16 November 2020 at 10:22:49 UTC, Jack Applegame wrote:
> Why doesn't it compile?
>> auto foo() {
>>     struct Foo {
>>         int a, b;
>>     }
>>     return Foo({
>>         a: 10,
>>         b: 20
>>     });
>> }
>
> Valid C++14:
>> auto foo() {
>>     struct Foo {
>>         int a, b;
>>     };
>>     return Foo({
>>         .a = 10,
>>         .b = 20
>>     });
>> }

Foo foo = {
          a: 10,
          b: 20
      }

is working in D at the moment. I can't wait for better 
initialization, named arguments to come into play too.

It's a shame that in some cases C is more expressive than D: 
https://github.com/gfx-rs/wgpu-native/blob/master/examples/triangle/main.c , it even allows to return a pointer to a struct literal.


More information about the Digitalmars-d mailing list