Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9301217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:57:52+00:00 2026-06-18T22:57:52+00:00

I’m trying to call an overloaded function which operates on function pointers that have

  • 0

I’m trying to call an overloaded function which operates on function pointers that have parameters with default values.

void originalFunction1 (int a = 0) {printf("I'm #1 and a is %d",a);}
void originalFunction2 () {printf("I'm #2");}

void overloadedFunction (void (*fptr)(void))
{
  fptr();
}

void overloadedFunction (void (*fptr)(int))
{
  overloadedFunction( (void(*)(void)) fptr);
}

int main() 
{
  overloadedFunction(originalFunction1);
  overloadedFunction(originalFunction2);

  // output is:
  // I'm #1 an a is -1073743272
  // I'm #2
}

As the answers to this question points out, default values are not part of the function signature and also can’t be repeated during the (function pointer -) parameter definition.
As my example shows, they can be cast away for calling, but they will then not be initialized to their default value.

Is there any way to work around this?

I can’t modify the original function but I know the default value.
I can modify both the main overloaded function as well as the redirects.
The fptr’s will always only be called without parameters.
In reality, there are more overloaded functions as also the return type differs, but I can cast that away more easily.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T22:57:53+00:00Added an answer on June 18, 2026 at 10:57 pm

    The short answer is no. The cast is legal, but the only thing
    you can do with the results is to cast them back to the orginal
    type. Default arguments do not change the signature of the
    function. They only enter into account at the call site, where
    they are passed if the client doesn’t provide an argument. The
    function itself is always called with the full set of arguments,
    which it clearly won’t be if you call it through the results of
    the cast.

    The usual answer here, if you have control of the sources, is to
    use overloading instead of default arguments. (I have heard
    arguments that you should always use overloading instead of
    default arguments.) So

    void originalFunction1( int a ) { ... }
    void originalFunction1() { originalFunction1( 0 ); }
    

    instead of what you have.

    Alternatively, you might be able to play games with templates:

    template <typename FunctionPtr>
    void overloadedFunction( FunctionPtr fptr )
    {
        fptr();
    }
    

    I’d prefer the first solution if you can use it, however.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have an autohotkey script which looks up a word in a bilingual dictionary
I'm trying to select an H1 element which is the second-child in its group
I have an array which has BIG numbers and small numbers in it. I
I have a text area in my form which accepts all possible characters from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.