Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I pass a pointer to a structure without angering the compiler?
    primarykey
    data
    text
    <p>I'm attempting to compile a simple C++ program using MinGW 4.7.2, but am frustrated by a deluge of errors and warnings.</p> <pre><code>/*\ program.h \*/ typedef struct { int member0; int member1; int member2; int member3; } structure; void function(&amp;structure); </code></pre> <hr> <pre><code>/*\ program.cpp \*/ #include "program.h" int main(void) { structure *instance; function(instance); } void function(&amp;structure) { // nothing } </code></pre> <p><code>function</code> takes the address of a <code>structure</code>. Pointer <code>instance</code> contains the address of a <code>structure</code> which is then passed to <code>function</code>.</p> <p>Simple, but the compiler is not happy.</p> <pre><code>g++ program.cpp In file included from program.cpp:1:0: program.h:8:14: error: variable or field 'function' declared void program.h:8:25: error: expected primary-expression before ')' token program.cpp: In function 'int main()': program.cpp:5:19: error: 'function' was not declared in this scope program.cpp: At global scope: program.cpp:8:14: error: variable or field 'function' declared void program.cpp:8:25: error: expected primary-expression before ')' token </code></pre> <p>What is <code>variable or field 'function' declared void</code> trying to tell me? <code>function</code> is obviously <code>void</code>, but how is that bad? I've spent several hours searching for these answers, but without success.</p> <p>How can I pass a pointer to a structure without making the compiler vomit?</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.
    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