Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<ol> <li><p>You can use pointers as Kingdom of Fish <a href="https://stackoverflow.com/questions/2538959/passing-structures-by-reference-c/2539024#2539024">suggested</a>. I just wanted to add that your documentation should indicate that these values are "outputs" even though they are parameters.</p></li> <li><p>You can use a tuple data-type. Here is a simple one:</p> <pre><code>typedef struct Tuple{void*a,*b;}*Tuple; Tuple tuple(void*a,void*b){ Tuple z=malloc(sizeof(struct Tuple)); z-&gt;a=a,z-&gt;b=b; return z; } </code></pre> <p>Beware though, that tracking dynamically allocating memory can be difficult, and unless you are using a <a href="http://www.hpl.hp.com/personal/Hans_Boehm/gc/" rel="nofollow noreferrer">garbage collector</a>, you need to be very careful.</p></li> <li><p>You can use a less-general data structure. For example, you could thread the indexes through the person-object:</p> <pre><code>struct Person;typedef struct Person*Person; struct Person{Person*prev_by_name,*next_by_name,*prev_by_age,*next_by_age; ...}; </code></pre> <p>Adding additional indexes (linked lists) becomes trivial, and if you give it some thought, you can make the preprocessor do most of the work for you.</p> <p>This method also gives you the ability to ask "who is the next-youngest-person after Dave"</p> <p>Finally, by threading the indexes in this way, all updates to a person's indexes will be kept together, which will make it easier to avoid synchronization bugs.</p></li> <li><p>You can use separate functions and simply "remember" to call them both. If this is for homework, and you haven't yet addressed how to return multiple values, then you might want to choose this "solution" simply because it's probably what your teacher is looking for.</p></li> </ol>
 

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