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 7657887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:07:21+00:00 2026-05-31T13:07:21+00:00

I have the following situation: void function(params) { #ifdef _MULTIPLAYER if (isConnected) { if

  • 0

I have the following situation:

void function(params)
{
  #ifdef _MULTIPLAYER
    if (isConnected)
    {
      if (isClient)
      {
        requestFunctionRemotely(params)
        return;
      }
      else if (isServer)
      {
        call realFunction(params) remotely on client;
      }
    }
  #endif

  realFunction(params);
}

realFunction(params)
{
  ...
}

With this situation I’m able to build my project either with single player instance or with multiplayer.

This approach has been used because function(params) is called all around my code, so in this way I just attach to the lowest possible level without having problems.

I had to split the function and realFunction because remote responses received by clients must be executed through realFunction to avoid loops (I could change the function prototype to add a flag but I would break a lot of code).

My concern is related to performance when disabling the _MULTIPLAYER define. I have A LOT of function(params) and I’ll call them thousand of times. I’ll have to use this approach for all of them. Will g++ optimize away the double call when it will find

function(params) {
  realFunction(params);
}

to

function(params) {
  // body of realFunction
}

and there is way to force it in every similar situation?

Just as a hint: I currently use the -O2 flag

  • 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-05-31T13:07:22+00:00Added an answer on May 31, 2026 at 1:07 pm

    If you want to be sure you could invert your pattern and use a template parameter. That way you are sure the compiler will remove the if (false) at compile time.

    template <bool isMulti>
    void Function(params) 
    { 
        if (isMulti)
            MultiFunction();
    
        // real function code
    } 
    
    void MultiFunction(params) 
    {  } 
    

    Note:

    If working with a class, you could move up the template parameter to the class for concision.

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

Sidebar

Related Questions

Suppose you have the following situation #include <iostream> class Animal { public: virtual void
i have the following situation : with my function i get an XML file
I have the following situation: typedef void (*F_POINTER)(ClassName*); class ClassName { public: F_POINTER f;
I have following situation class base { public: virtual void Accepted(SOCKET s) //// Event
i have the following situation: public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.createcharacter); //Referenciando Items
I have following situation: I have loged user, standard authentication with DB table $authAdapter
I have following situation. A main table and many other tables linked together with
I have following situation. In a constructor of a pseudo class I attach a
I have following situation (simplified, of course): MyDomain.groovy: class MyDomain { MyAnotherDomain anotherDomain //
I have following situation, String a=<em>crawler</em> <em> Yeahhhhh </em></a></h3><table; System.out.println(a.indexOf(</em>)); It returns the 11

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.