Returning constant / literal struct value (pod)

Cecil Ward d at cecilward.com
Fri Mar 9 21:30:53 UTC 2018


Can we return a literal struct value straight from a return 
statement ?

ie something like
mystruct_t myfunc()
     { // ... blah
     return { field1: val1, field2: val2; };
     }
assuming that the return type is defined suitably, and the struct 
is just a C struct, plain-old-data (ie not a C++-like class).

I've had to set up a throwaway const item, initialised, and then 
had to return that.


More information about the Digitalmars-d-learn mailing list