What's best practice to use compound literals with structs and C-APIs?
    Jacob Carlborg 
    doob at me.com
       
    Thu May  2 19:27:03 UTC 2019
    
    
  
On 2019-05-01 14:47, Robert M. Münch wrote:
> I use some C library that uses structs and many functions that use 
> pointer to structs as arguments:
> 
> struct A {...};
> myfunc(A *myA);
> 
> In C you can do this to get a lvalue:
> 
> myfunc(&(A){...});
> 
> In D this doesn't work and I get an "is not an lvalue and cannot be 
> modified".
> 
> What's the correct D-ish way in such a case?
struct A {...};
myfunc(A *myA);
What about doing this:
auto a = A(/* set any values */);
myfunc(&a);
-- 
/Jacob Carlborg
    
    
More information about the Digitalmars-d-learn
mailing list