digitalmars.D.learn - How do you take the address of a struct in D?
- Enjoys Math (4/4) Feb 05 2016 SDL_RenderCopy(...) takes two pointers to SDL_Rect's,
- =?UTF-8?Q?Ali_=c3=87ehreli?= (21/26) Feb 05 2016 Does it compile and produce an incorrect result? For it to compile, the
- Enjoys Math (2/7) Feb 05 2016 Got it. I was taking the address of a return-by-copy property.
SDL_RenderCopy(...) takes two pointers to SDL_Rect's, I have a property method in another class returning the SDL_Rect equivalent of a Box (my structure). Taking ampersand on the left of a call to the property does not give the address (&).
Feb 05 2016
On 02/05/2016 03:53 PM, Enjoys Math wrote:SDL_RenderCopy(...) takes two pointers to SDL_Rect's, I have a property method in another class returning the SDL_Rect equivalent of a Box (my structure).Returning by reference or by value?Taking ampersand on the left of a call to the property does not give the address (&).Does it compile and produce an incorrect result? For it to compile, the returned object must be an lvalue. The following works (not the commented-out part): import std.stdio; struct S { } S s; S returnsCopy() { return s; } ref S returnsRef() { return s; } void main() { // auto addr = &returnsCopy(); auto addr = &returnsRef(); writeln(addr); } Ali
Feb 05 2016
On Friday, 5 February 2016 at 23:53:15 UTC, Enjoys Math wrote:SDL_RenderCopy(...) takes two pointers to SDL_Rect's, I have a property method in another class returning the SDL_Rect equivalent of a Box (my structure). Taking ampersand on the left of a call to the property does not give the address (&).Got it. I was taking the address of a return-by-copy property.
Feb 05 2016