justin = { main feed , music , code , askjf , pubkey };
Ask Justin Frankel
No reasonable question unanswered since 2009!

Suggested topics: programming, music, sleep, coffee, etc.

Note: please do not ask questions about REAPER features, bugs or scheduling, use the forums instead.


Name: Ask: Human (enter yes):
[back to index] | [unreplied] | [replied] | [recent comments] | [all]

Question: Do you use to return objects from functions? Is there anything wrong with this practice? Example: pastebin.com/x1SB2bZ6
Asked by Rodrigo (189.26.130.x) on August 13 2011, 12:33pm
Reply on August 13 2011, 5:22pm (edited at August 13 2011, 7:51pm):
    I don't usually return structs, just out of habit, since at one point in my life it wasn't always possible.

    As far as performance/code generation go goes, assuming the structure type is simple (and doesn't have copy constructors, destructors, etc), it appears that they should compile to very close to the same code. Note that the form of:
      RECT r = someFunc(); // or: RECT r; someFunc2(&r);
      printf("%d %d",r.left,r.top);
    
    is often faster / smaller than:
      printf("%d %d",someFunc().left,someFunc().top);
    
    ...due to the fact that the compiler might call the code in someFunc twice, unless it is a trivially inlineable function that does change any state... that style is relying more on the compiler.

Comment:
    Your Name:   -- Site Owner's Name:  (for human-verification)

    Comment:    

    
  
[back to index] | [unreplied] | [replied] | [recent comments] | [all]
Copyright 2025 Justin Frankel. | RSS