The key is in this:
previous implicit declaration of ‘point_forward’ was here
On line 96 you have:
point_forward(m); // where m is a mem_ptr;
Since the compiler hasn’t yet seen a function declaration for point_forward(m)
, it “implicitly defines” (ie, assumes) a function that returns an int:
int point_forward(mem_ptr m);
This conflicts with the definition later:
void point_forward (mem_ptr m) {
To fix this, you can either:
- Put an explicit declaration somewhere before line 96:
void point_forward(mem_ptr m);
This will tell the compiler how to treatpoint_forward()
when it sees it on line 96, even though it hasn’t yet seen the function implementation. - Or, define the whole function above line 96 (move the function definition from line 134 onwards to above line 96).
Here is a little bit more about declaring functions.
Generally, for style, I would either:
- If you don’t want to use
point_forward()
in any other C files, define it in full:static void point_forward(mem_ptr m) { ..function body goes here.. }
at the top of the source file. - If you want to use
point_forward()
in other C files, put a forward declaration:void point_forward(mem_ptr m);
in a header file for other files to include.