Passing struct to function

2018-06-13 Thread Michał via Digitalmars-d-learn
When I pass my struct to function something is going wrong. I don't know how to fix it. Code: import std.stdio; void print(ref Vector v, string s){ writefln("%s==%s%s", &v.x, v.ptr, s); } struct Vector { int x; int* ptr; this(this) {

Re: Passing struct to function

2018-06-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/13/18 10:43 AM, Michał wrote: When I pass my struct to function something is going wrong. I don't know how to fix it. Code: import std.stdio; void print(ref Vector v, string s){     writefln("%s==%s    %s", &v.x, v.ptr, s); } struct Vector { int x; int* ptr; this(th

Re: Passing struct to function

2018-06-13 Thread Michał via Digitalmars-d-learn
On Wednesday, 13 June 2018 at 16:40:51 UTC, Steven Schveighoffer wrote: On 6/13/18 10:43 AM, Michał wrote: When I pass my struct to function something is going wrong. I don't know how to fix it. Code: import std.stdio; void print(ref Vector v, string s){     writefln("%s==%s    %s", &v.

Re: Passing struct to function

2018-06-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/13/18 1:08 PM, Michał wrote: On Wednesday, 13 June 2018 at 16:40:51 UTC, Steven Schveighoffer wrote: On 6/13/18 10:43 AM, Michał wrote: When I pass my struct to function something is going wrong. I don't know how to fix it. Code: import std.stdio; void print(ref Vector v, string s){   

Re: Passing struct to function

2018-06-13 Thread Michał via Digitalmars-d-learn
On Wednesday, 13 June 2018 at 17:37:44 UTC, Steven Schveighoffer wrote: Hm... the only way to do it in D is to provide a function that checks whether the small vector optimization is in play, and return a pointer/slice to itself. With D it is possible to alias the getter function that provi