Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
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.

List of 21 messages in thread
TopicAuthorDate
OT: C parameter by reference or by value            01/01/70 00:00      
   RE: OT: C parameter by reference or by value            01/01/70 00:00      
      Parameters on stack            01/01/70 00:00      
      RE: OT: C parameter by reference or by value            01/01/70 00:00      
   Whats wrong with good ol pointer/global?            01/01/70 00:00      
      RE: Whats wrong with good ol pointer/global?            01/01/70 00:00      
         RE: Whats wrong with good ol pointer/global?            01/01/70 00:00      
            RE: Whats wrong with good ol pointer/global?            01/01/70 00:00      
               RE: Whats wrong with good ol pointer/global?            01/01/70 00:00      
            Pointer vs Reference            01/01/70 00:00      
               RE: Pointer vs Reference            01/01/70 00:00      
                  RE: Pointer vs Reference            01/01/70 00:00      
                     RE: Pointer vs Reference            01/01/70 00:00      
         RE: Whats wrong with good ol pointer/global?            01/01/70 00:00      
         RE: Whats wrong with good ol pointer/global?            01/01/70 00:00      
            RE: recursive functions            01/01/70 00:00      
   RE: OT: C parameter by reference or by v            01/01/70 00:00      
      RE: OT: C parameter by reference or by v            01/01/70 00:00      
      RE: OT: C parameter by reference or by v            01/01/70 00:00      
         RE: OT: more useful to have explicit ..            01/01/70 00:00      
         RE: OT: C parameter by reference or by v            01/01/70 00:00      

Back to Subject List