Creating a sysctl variable ?

This is a discussion on Creating a sysctl variable ? within the C Programming forums, part of the General Programming Boards category; Hi, I'd need to create a variable that keeps track of something happening in my function. So I don't want ...

  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    3

    Creating a sysctl variable ?

    Hi,

    I'd need to create a variable that keeps track of something happening in my function. So I don't want my variable to be initialized each time the function is called, I want it to stay.

    I guess I can create a sysctl variable for that purpose. How do I do that ?

    The thing is, the function is part of the linux TCP stack, and I don't know where the most global variable are declared. I'm a beginner in C programming & Linux.
    Last edited by taupin; 06-28-2008 at 06:02 PM.

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    I think perhaps you just want a local static variable in your function.

  3. #3
    Registered User
    Join Date
    Jun 2008
    Posts
    3
    Okay, but where do I declare it ? I don't want it to be declared in a function where it'd intinialized several times. The function I'm talking about will be part of the Linux TCP stack. I'm a beginner in programming.

  4. #4
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Quote Originally Posted by taupin View Post
    Okay, but where do I declare it ?
    Inside your function like I said.

    Quote Originally Posted by taupin View Post
    I don't want it to be declared in a function where it'd intinialized several times.
    Read up on static variables. They are akin in ways to global variables with limited scope. They are initialized once and then only altered as you change them.

    Quote Originally Posted by taupin View Post
    The function I'm talking about will be part of the Linux TCP stack. I'm a beginner in programming.
    Quite a paradox.

  5. #5
    Registered User
    Join Date
    Jun 2008
    Posts
    3
    Alright, I didn't know about static variables. Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C variable
    By webstarsandeep in forum C Programming
    Replies: 1
    Last Post: 10-23-2008, 02:26 AM
  2. Static Local Variable vs. Global Variable
    By arpsmack in forum C Programming
    Replies: 7
    Last Post: 08-21-2008, 04:35 AM
  3. Problem with a char variable set as a letter
    By 7smurfs in forum C++ Programming
    Replies: 6
    Last Post: 12-10-2004, 01:25 PM
  4. Static global variable acting as global variable?
    By Visu in forum C Programming
    Replies: 2
    Last Post: 07-20-2004, 09:46 AM
  5. creating a filename based on a variable
    By Waldo2k2 in forum C++ Programming
    Replies: 3
    Last Post: 05-22-2002, 06:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21