invalid application of 'sizeof' to incomplete type 'struct array[]' <p>I am trying to organize my project by splitting commands up into separate files for easier maintenance. The issue I am having is trying to iterate over the array of commands defined at compile time. I have created a dumbed down example that reproduces the error I am getting.</p> <pre><code>. ├── CMakeLists.txt ├── commands │ ├── CMakeLists.txt │ ├── command.c │ ├── command.h │ ├── help_command.c │ └── help_command.h └── main.c </code></pre> <h3>./CMakeLists.txt</h3> <pre><code>PROJECT(COMMAND_EXAMPLE) SET(SRCS main.c) ADD_SUBDIRECTORY(commands) ADD_EXECUTABLE(test ${SRCS}) </code></pre> <h3>commands/CMakeLists.txt</h3> <pre><code>SET(SRCS ${SRCS} command.c help_command.c) </code></pre> <h3>commands/command.h</h3> <pre><code>#ifndef COMMAND_H #define COMMAND_H struct command { char* name; int (*init)(int argc, char** argv); int (*exec)(void); }; extern struct command command_table[]; #endif </code></pre> <h3>commands/command.c</h3> <pre><code>#include "command.h" #include "help_command.h" struct command command_table[] = { {"help", help_init, help_exec}, }; </code></pre> <h3>commands/help_command.h</h3> <pre><code>#ifndef HELP_COMMAND_H #define HELP_COMMAND_H int help_command_init(int argc, char** argv); int help_command_exec(void); #endif </code></pre> <h3>commands/help_command.c</h3> <pre><code>#include "help_command.h" int help_command_init(int argc, char** argv) { return 0; } int help_command_exec(void) { return 0; } </code></pre> <h3>./main.c</h3> <pre><code>#include &lt;stdio.h&gt; #include "commands/command.h" int main(int argc, char** argv) { printf("num of commands: %d\n", sizeof(command_table) / sizeof(command_table[0])); return 0; } </code></pre> <p>If you run this</p> <pre><code>mkdir build &amp;&amp; cd build &amp;&amp; cmake .. &amp;&amp; make </code></pre> <p>the following error occurs</p> <pre><code>path/to/main.c:6:40: error: invalid application of 'sizeof' to incomplete type 'struct command[]' </code></pre> <p>So, how do I iterate over <code>command_table</code> if I can't even determine the number of commands in the array?</p> <p>I realize there are other posts out there with this same error, but I've spent a while now trying to figure out why this doesn't work and continue to fail:</p> <ul> <li><a href="http://stackoverflow.com/questions/8915230/invalid-application-of-sizeof-to-incomplete-type-with-a-struct">invalid-application-of-sizeof-to-incomplete-type-with-a-struct</a></li> <li><a href="http://stackoverflow.com/questions/5240435/invalid-application-of-sizeof-to-incomplete-type-int-when-accessing-intege">invalid-application-of-sizeof-to-incomplete-type-int-when-accessing-intege</a></li> </ul>