I have this include file (memory .h
)
#ifndef MEMORY_H
#define MEMORY_H
#ifdef __cplusplus
extern "C" {
#endif
typedef struct mmemory {
int* cells;
int* current_cell;
int cells_number;
} memory;
void memory_init(memory* mymemory, int size);
void step_left(memory* mymemory, int steps);
void step_right(memory* mymemory, int steps);
void cell_inc(memory* mymemory, int quantity);
void print_cell(memory* mymemory);
void get_char(memory* mymemory);
#ifdef __cplusplus
}
#endif
#endif /* MEMORY_H */
And this implementation file (memory.c
)
#include <stdlib.h>
#include "memory.h"
void
memory_init (memory* mymemory, int size)
{
mymemory->cells = (int*) malloc (sizeof (int) * size);
mymemory->cells_number = size;
mymemory->current_cell = (int*) ((mymemory->cells_number / 2) * sizeof (int));
}
... //other function definitions follow
When I try to compile memory.c
I get this error for each and every function definition
src/memory.c:5: error: expected ')' before '*' token
where line 5 is the function definition for memory_init()
Can someone please tell me why I'm getting this error?
To fix this error, check the statement which should not be terminated and remove semicolons. To fix this error in this program, remove semicolon after the #define statement.
– Adjust the Curly Braces To Fix the Expected Unqualified Id Error. You should match the opening and closing curly braces in your code to ensure the right quantity of brackets. The code should not have an extra or a missing curly bracket.
Typically this means that the library that contains 'cout' isn't present in your code. You can read about 'cout' declarations here: http://www.cplusplus.com/reference/iostream/cout/ expected ';' before '}' token. This typically means that there is statement missing a semicolon ';'.
expected” This error occurs when something is missing from the code. Often this is created by a missing semicolon or closing parenthesis.
Because the system memory.h
is shadowing your memory.h
, causing the #include
to succeed without declaring your types. Several possible fixes:
#include <myproj/memory.h>
).#include
precedence rules for filenames wrapped in "
to take effect.This answer is really late, but I encountered a similar problem.
I think your problem is related to a typo in your .h file where you declare a struct mmemory. If you remove that extra 'm' it should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With