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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:18:41+00:00 2026-05-16T01:18:41+00:00

I am unsure about how function calls are translated and I am afraid that

  • 0

I am unsure about how function calls are translated and I am afraid that passed variables are copied into local variables when they don’t need to be. I could avoid unnecessary copying by using global variables, but that cannot be a good solution…

1) When variables are not changed in the target function, would it be better to pass them as pointers, references, or const?

void fkt1(int i, int j){
  do_something();
  printf("%d", i+j);
}

int main(){
  int i = 5;
  int j = 6;
  fkt1(i, j);
}

2) Is it expensive to pass variables to a function when they are not used within it. E.g., to keep a common interface, such as:

template <typename T>
void fkt2(T a, T b, int len = -1){ 
  do_something();
  printf("%d", a+b);
}

template<>
void fkt2<char*>(char* a, char* b, int len){
  do_something();
  strcpy(a+len, b);
  printf("%s", a);
}

or

class base{
public:
  virtual bool calc(int i, int j, int k, int l) = 0;
  base *next1;
  base *next2;
}

class derived1 : public base{
public:
  bool calc(int i, int j, int k, int l){
    return (next1->calc(int i, int j, int k, int l) || 
            next2->calc(int i, int j, int k, int l))
  }
}    

class derived2 : public base{
public:
  bool calc(int i, int j, int k, int l){
    return (return i+j > 5)
  }
}    

class derived3 : public base{
public:
  bool calc(int i, int j, int k, int l){
    return (return j*k < l)
  }
}    

Comments are much appreciated.

  • 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-16T01:18:41+00:00Added an answer on May 16, 2026 at 1:18 am

    Don’t worry about the performance issues at this point.

    Focus on the algorithmic cost of your function, not the trivial things: guessing performance issues is a bad idea.

    If you really encounter performance issues and have maintainable code, it will still be time to improve it.

    Now to really answer the question:

    You may pass const references when the object you have to pass really shouldn’t be copied. If you have to pass integers, or simple structs (aka. small types), using a const reference or even a pointer is probably too much work: you will clutter the code with uneeded complexity were the compiler would probably have optimized things anyway.

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

Sidebar

Related Questions

When I am unsure about some thing for a project, I usually use a
I want place ads in my website, but I'm unsure about the common practices
A question yesterday about doubled-checked locking started a chain of thoughts that left me
I am unsure about how to generate a random n digit integer in Java
Unsure if I've phrased this correctly, but in the callback how do I reference
I'm a little unsure how the open source licensing stuff works. If I were
I am unsure if this is even possible, but I thought I would ask.
Sorry if this is a comp-sci 101 question. I'm just unsure if I'm missing
In ASP.NET 2, I've used Field Validators, and RequiredField validators, but I'm unsure of
I'm working with jQuery for the first time and need some help. I have

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.