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

  • Home
  • SEARCH
  • 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 3310948
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:49:09+00:00 2026-05-17T21:49:09+00:00

gcc 4.4.4 c89 I have the following code and 2 structures that have to

  • 0

gcc 4.4.4 c89

I have the following code and 2 structures that have to be filled.

I have 3 functions that will fill the handles for each of the devices.

However, the device_type structure will need to increment from where the last function finished.

For example:

load_resources() starts at 0 and finishes at 9
    dev_types starts at 0 and finishes at 9

load_networks()  starts at 0 and finishes at 9
    dev_types starts at 10 and finishes at 19

load_controls()  starts at 0 and finishes at 9  
    dev_types starts at 20 and finishes at 29

However, as I don’t want to use a static or global variable is there any way I can increment a
value for this. So it will start where the last function finished.

Many thanks for any suggestions,

#define NUMBER_OF_DEVICES 10
#define NUMBER_OF_TYPES 3 /* resources
                             networks
                             controls */

int events(int evt);

int load_resources();
int load_networks();
int load_controls();

static struct device_table {
    int resource_handle;
    int network_handle;
    int control_handle;
} dev_tbl[NUMBER_OF_DEVICES];

struct device_types {
    size_t id;
    int dev_handle;
    int dev_type;
}dev_types[NUMBER_OF_DEVICES * NUMBER_OF_TYPES];

enum dev_name_types {RESOURCE, NETWORK, CONTROL};

/* Simulates the API calls, by returning a dummy handle */
int get_resources();
int get_networks();
int get_controls();

int main(void)
{
    srand(time(NULL));

    load_resources();
    load_networks();
    load_controls();

    return 0;
}

int load_resources()
{
    size_t i = 0;

    for(i = 0; i < NUMBER_OF_DEVICES; i++) {
        dev_tbl[i].resource_handle = get_resources();
        printf("dev_tbl[i].resource_handle [ %d ]\n", dev_tbl[i].resource_handle);
        dev_types[i].id = i;
        dev_types[i].dev_handle = dev_tbl[i].resource_handle;
        dev_types[i].dev_type = RESOURCE;
    }
}

int load_networks()
{
    size_t i = 0;

    for(i = 0; i < NUMBER_OF_DEVICES; i++) {
        dev_tbl[i].network_handle = get_networks();
        printf("dev_tbl[i].network_handle [ %d ]\n", dev_tbl[i].network_handle);
        dev_types[i].id = i;
        dev_types[i].dev_handle = dev_tbl[i].network_handle;
        dev_types[i].dev_type = NETWORK;
    }
}

int load_controls()
{
    size_t i = 0;

    for(i = 0; i < NUMBER_OF_DEVICES; i++) {
        dev_tbl[i].control_handle = get_controls();
        printf("dev_tbl[i].control_handle [ %d ]\n", dev_tbl[i].control_handle);
        dev_types[i].id = i;
        dev_types[i].dev_handle = dev_tbl[i].control_handle;
        dev_types[i].dev_type = CONTROL;
    }
}
  • 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-17T21:49:09+00:00Added an answer on May 17, 2026 at 9:49 pm

    Why not change the prototypes to something like:

    void load_resources(int*)
    

    (they’re not actually returning anything) then, in your main code, have:

    int base = 0;
    load_resources (&base);
    load_networks (&base);
    load_controls (&base);
    

    Each function is then responsible for using and updating *base like this:

    void load_resources (int *pBase) {
        size_t i = 0;
    
        for(i = 0; i < NUMBER_OF_DEVICES; i++, (*pBase)++) {  // <-- see here!
            dev_tbl[i].resource_handle = get_resources();
            printf("dev_tbl[i].resource_handle [ %d ]\n", dev_tbl[i].resource_handle);
            dev_types[*pBase].id = i;
            dev_types[*pBase].dev_handle = dev_tbl[i].resource_handle;
            dev_types[*pBase].dev_type = RESOURCE;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

gcc 4.4.3 c89 I have some functions that initialize some hardware and return either
gcc 4.4.4 c89 I have the following function but I cannot free the memory.
Using gcc 4.4.3 c89: I am just working on the following code below: I
gcc 4.4.4 c89 However, I am having a problem trying to display all the
I have the following program. However, I can't understand why I have to pass
gcc 4.4.3 c89 linux I am using log4c and have placed the inc and
gcc 4.4.4 c89 I have always thought of using malloc for the life of
gcc 4.4.4 c89 I am just wondering is there any standard that should be
g++ (GCC) 4.6.0 I have the following class and I am trying to initialize
I tried the following code on gcc 4.4.5. If the member 'data' is not

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.