www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Struct initialization extra comma - should it compile

reply JN <666total wp.pl> writes:
         struct Foo
         {
             int x, y, z;
         }

         void main()
         {
              Foo bar = Foo(1,);
         }

This compiles without syntax errors, is this expected?
Apr 25 2021
next sibling parent Bastiaan Veelo <Bastiaan Veelo.net> writes:
On Sunday, 25 April 2021 at 13:39:54 UTC, JN wrote:
         struct Foo
         {
             int x, y, z;
         }

         void main()
         {
              Foo bar = Foo(1,);
         }

 This compiles without syntax errors, is this expected?
Yes, the [specification](https://dlang.org/spec/declaration.html#StructInitializer) is like this: ``` StructMemberInitializers: StructMemberInitializer StructMemberInitializer , StructMemberInitializer , StructMemberInitializers ``` — Bastiaan.
Apr 25 2021
prev sibling parent Paul Backus <snarwin gmail.com> writes:
On Sunday, 25 April 2021 at 13:39:54 UTC, JN wrote:
         struct Foo
         {
             int x, y, z;
         }

         void main()
         {
              Foo bar = Foo(1,);
         }

 This compiles without syntax errors, is this expected?
Yes, D allows trailing commas in argument lists.
Apr 25 2021