Note that there are some explanatory texts on larger screens.

plurals
  1. POHowto handle typedefs without include headers in headers
    primarykey
    data
    text
    <p>As for working on a larger project, I want to throw in some own types (e.g. <code>myType</code>). The "rushing in"-approach would be, to put those typedefs into an header (lets say <code>myType.h</code>), together with a bunch of functions working on those types.</p> <p>If I use the new type somewhere, I include <code>myType.h</code> to my source-file. Fine.</p> <p>But if I want to use the new type somewhere as an argument in a function-signature, I need to include the <code>myType.h</code> to the header of the module containing the function. With one or another typedef, this seems to be okay for me, but the more types I have, the more includes in headers I need, possible including further header, while using type including other own types. This is resulting in what I call "<strong>dependency hell</strong>".</p> <p>Is there a clever, stylish, best practice, what-so-ever way to solve this dilemma? </p> <p>I'm aware of the possibility to pass those types as void-pointer, casting them back inside the function, but then I loose important type-checking from the compiler.</p> <p>Furher, <code>extern</code> is considered worst-practice around here.. </p> <p><strong>EDIT:</strong></p> <p>In detail:</p> <p><code>myType.h</code>:</p> <pre><code>#include "otherType.h" typedef struct { char Name[32]; int Size; otherType someType; } myType; processSomeHow(myType _myType, int NewSize); </code></pre> <p><code>otherType.h</code></p> <pre><code>#define SOME_CONST 32 typedef struct { [...] } otherType; </code></pre> <p><code>someModule.h</code>:</p> <pre><code>#include "myType.h" int specialProcessSomeHow(myType _myType); </code></pre> <p><code>someModule.c</code>:</p> <pre><code>int specialProcessSomeHow(myType _myType) { int Size = 64; return(processSomeHow(_myType, Size)); } </code></pre> <p>Now I include <code>otherType.h</code> indirectly to <code>someModule.h</code>, even worse, I include it to every module, that includes <code>someModule.h</code>. Now I have a <code>SOME_CONST</code> everywhere and it's hard to figure out, from where it comes. I have to maintain two include trees.</p>
    singulars
    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