Silly struct behaviour

Jacob Carlborg via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jul 13 23:21:28 PDT 2017


On 2017-07-13 20:07, JN wrote:
> Consider:
> 
> struct Foo
> {
>      int bar;
> }
> 
> void processFoo(Foo foo)
> {
> }
> 
> void main()
> {
>      Foo f = {bar: 5};
>      processFoo(f);                // ok
>      processFoo(Foo(5));           // ok
>      processFoo({bar: 5});         // fail
>      processFoo(Foo({bar: 5}));    // fail
> }
> 
> 
> Whyyyy D? It makes no sense, the compiler knows what is the type of the 
> first processFoo arg anyway...

https://github.com/dlang/DIPs/pull/71

-- 
/Jacob Carlborg


More information about the Digitalmars-d-learn mailing list