| ??? 01/04/04 14:47 Read: times |
#61895 - RE: OT: C parameter by reference or by v Responding to: ???'s previous message |
A decision must be made: Do you optimise your program for speed or for clarity, because these two are usually in opposition, and "halfway" solutions are more often "slow and ugly" than "fast and clean".
If you want tidy - then by value. If you want fast - inline it. By reference has only one serious use, and is really hard to replace. That is when your function returns more than one value or is meant to modify one of its parameters. So: void roots(float a,float b,float c,float* x1,float* x2) is obviously better than typedef struct {float x0, float x1} tworoots; tworoots* roots(float a,float b,float c); and void normalize(int* x); called as normalize(&x); is obviously better than int normalize(int x); called as x=normalize(x); Calling by reference is not really yet another way of optimizing the program. It's a specific tool for use in specific situations. |



