Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 3rd, 2008, 11:07 AM   #1
kurt
Programmer
 
Join Date: Oct 2005
Posts: 68
Rep Power: 3 kurt is on a distinguished road
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.
kurt is offline   Reply With Quote
Old Jul 3rd, 2008, 3:50 PM   #2
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,033
Rep Power: 5 lectricpharaoh will become famous soon enough
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
lectricpharaoh is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:01 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC