![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Oct 2005
Posts: 68
Rep Power: 3
![]() |
Function Default Values efficient?
Let's say I have a function that all it's parameter have default values.
So, is there a performance difference between: func( ); func(1, 2, 3); Does it save the need to copy the values of the parameters when the function is called? By the way, I set the default values to member variables. Overloading is an option, but the only difference is to use overidden parameter values (vs) using member variables. |
|
|
|
|
|
#2 |
|
Caffeinated Neural Net
![]() Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,033
Rep Power: 5
![]() |
Re: Function Default Values efficient?
Default parameter values are just a shorthand notation. The compiler will generate the appropriate default value and pass it, just as if you'd called the function with the default value. In other words, it compiles to the same object code.
Also, be aware that using default values can sometimes lead to ambiguity over which function to call if you're using overloading, so you need to keep this in mind, as it may be an issue: void foo(int bar = 1); void foo(void); . . foo(); // which function is being called?
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot. - Vaarsuvius, Order of the Stick |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Assigning a class function as a callback function | core8583 | C++ | 4 | Jun 18th, 2008 7:20 PM |
| Need help starting a recsursive/backtracking function | codylee270 | C++ | 22 | Oct 31st, 2006 8:16 PM |
| Function Overloading, Copy Constructors, Default Arguements | RemoteC2 | C++ | 5 | Aug 15th, 2006 12:09 PM |
| change the empty function from the old format to the new format | powah | Sed and Awk | 0 | Jun 23rd, 2005 11:10 AM |
| Returning a value from a variable to the main function | colt | C | 3 | Apr 28th, 2005 7:56 AM |