Thread: Keeping track of static external structure

  1. #1
    pwilfred
    Guest

    Angry Keeping track of static external structure

    Hi guys...I need some quick help getting going on this. I need to create an array of 20 structures and keep track of them as static variables. The structure is as follows: (it's object oriented C)

    typedef struct sched_unit
    {
    int unitNumber;
    int position;
    int numRecords;
    FINO_T *schedObj;
    FINOCLIST_PTR_T errorList;
    } SCHED_UNIT_T;

    The schedObj is the main data that i need to keep track of. These objects will be added and deleted from the array as needed. Do I need to declare another static pointer to this structure and then allocate memory for it as needed. What is the best way to go about doing this??

    John

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Don't bother with static. Use a global list pointer.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    pwilfred
    Guest
    care to expand on that?

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Sure. Make a global variable.

    SCHED_UNIT_T *myData;

    If you want to "protect" this, make your functions that modify this data static so they can only be called from within the same file. Make an accessor functions that aren't static that can be used to manipulate the data safely.

    Actually though, from the description of it, if all you need is an array of 20 max, just use an array instead of a pointer.

    SCHED_UNIT_T myData[20];

    Then make functions that "add" or "remove" items from the list. You could treat it like a stack and just use a variable some place to keep track of the total number of items in the array.

    int dataCount;

    Then just check to see if your array is full before you add, or empty before you remove.

    When I initally said 'list poitner', I was thinking you were using a linked list, not an array.

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    pwilfred
    Guest
    Do you have to declare the array as static?

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by pwilfred
    Do you have to declare the array as static?
    1) Yes, if you're going to have it localized to a function.
    2) No, not if it's global, or if it's in the main fuction and you're passing it to other functions.

    Quzah.
    Hope is the first step on the road to disappointment.

  7. #7
    pwilfred
    Guest
    Thanks a lot. I will try that.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 05:42 PM
  2. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM
  3. Serial Communications in C
    By ExDigit in forum Windows Programming
    Replies: 7
    Last Post: 01-09-2002, 10:52 AM
  4. vector static abstract data structure in C?
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 11-05-2001, 05:02 PM
  5. keeping track of # of files
    By blind_collision in forum C Programming
    Replies: 1
    Last Post: 10-13-2001, 09:10 AM