Error: expected ')' before '*' token

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 every function definition

src / memory.c: 5: error: expected ')' before '*' token

where line 5 is the function definition for memory_init()

Can someone tell me why I get this error?

+6
c
source share
3 answers

As the memory.h system obscures your memory.h , causing #include to succeed without declaring your types. Several possible fixes:

  • Rename your file — perhaps at best to reduce potential confusion.
  • Include the file through the prefix subdirectory (for example, #include <myproj/memory.h> ).
  • Move the file to the same directory as the source file so that the #include rules for file names wrapped in " take effect. "
  • Make sure your C preprocessor includes path parameters, place the path to the project header before the paths to the system header.
+14
source share

This answer is very late, but I ran into a similar problem.

I think your problem is with a typo in your .h file, where you declare the mm structure. If you remove this extra "m", it should work.

+3
source share

In the code you defined so for memory.h

 #ifndef MEMORY_H #define MEMORY_H ... ... #endif 

If any of your other files that you use in your project have the same #define ie MEMORY_H, you may get this error.

Decision:

 #ifndef XYZ_MEMORY_H #define XYZ_MEMORY_H ... ... #endif 
-one
source share

All Articles