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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:39:42+00:00 2026-05-15T09:39:42+00:00

Keeping track of how many times a function is called is easy when passing

  • 0

Keeping track of how many times a function is called is easy when passing the counter as an argument into the function. It’s also easy when returning a one from the called function. But, I do not want to go that route. The reason behind this is because it seems like bad programming (letting the function know too much information). Is there a better way to keep track of how many times this function has been called?

I’m just looking for concepts that I could study. Providing code examples is not neccessary, but might be helpful.

Edit: I’m not actually looking for profiling tools. Let me add some code to get my point across. Because scope for funcCounter ends in main, I have no way of getting back a variable from myFunction that will increment funcCounter. I could possibly return 1 from myFunction and then increment funcCounter that way, but this doesn’t seem like very good programming. Is there another way to do it?

int main()
{
int funcCounter = 0;
char *mystring = "This is a silly function.";
myFunction(mystring);
cout << "Times function is called: " << funcCounter << endl;
    return 0;
}

void myFunction(char *mystring)
{
cout << mystring << endl;
}
  • 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-15T09:39:43+00:00Added an answer on May 15, 2026 at 9:39 am

    Have a static variable in your function and keep incrementing it each time the function in called.

    void my_Function(void) {
        static unsigned int call_count = 0;
        call_count++;
    }
    

    If you want to do it for debugging reasons, then there are tools like gcov which do this for you. (I’m pretty sure Microsoft doesn’t have an alternative bundled with Microsoft Visual C++)

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

Sidebar

Related Questions

I have a User model, that may have many activities ( I'm keeping track
I am keeping track of pairs of ints and NSUIntegers as array indexes and
I have trouble keeping track of the properties of a Model instance. For example
I have a fairly basic TCP server keeping track of a couple connections and
I have a bunch of Thingy objects that I'm keeping track of using long
I'm writing a FUSE plugin in C. I'm keeping track of data structures in
I need to keep track of which user has visited which page how many
I've been reading around the web about different alternatives to keeping track of users
PokerFrame (called from a viewer class) worked perfectly, but once I tried to convert
I have a column dedicated to keeping track of which messages on my project

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.