Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to conditionally determine which functions are called at compile time?
    primarykey
    data
    text
    <p>I'm working on implementing a very, <em>very</em> basic component system in <strong>C</strong>, but now I am at a point where I want to 'dynamically' call some functions. The set-up is very easy: the main program is simply an endless while loop, in which some conditions are checked and in which a "process" function is called for each enabled component.</p> <p>For example, now it works like this:</p> <pre><code>while (1) { input_process(); network_process(); graphics_process(); } </code></pre> <p>But I want to separate it into separate components, and somehow define in a central place which parts are used. This could be done with simple defines, like so:</p> <pre><code>#define HAS_NETWORK ... while (1) { input_process(); #ifdef HAS_NETWORK network_process(); #endif graphics_process(); } </code></pre> <p>As you can see this is alright for 1 or maybe only a few components, but if I want to do this for all of these (input, network and graphics) and additional components in the future, I would have to put separate #ifdefs in there for each of them, and that's quite tedious.</p> <p>In pseudo code, what I'm trying to accomplish is the following:</p> <pre><code>components = {'input', 'network', 'graphics'} ... foreach component in components execute component_process() </code></pre> <p>This way components could easily be added in the future. I don't really mind if the checking is done compile time or run time (although I obviously prefer compile time, but I can imagine run time is easier to implement). I have no idea how to even start.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload