tags:

views:

85

answers:

2

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?

+5  A: 

Because the system memory.h is shadowing your memory.h, causing the #include to succeed without declaring your types. Several possible fixes:

  • Rename your file -- probably for the best in any case, to reduce potential confusion.
  • Include your file via a prefix subdirectory (e.g., #include <myproj/memory.h>).
  • Move your file into the same directory as the source file, allowing the #include precedence rules for filenames wrapped in " to take effect.
  • Ensure that your C pre-processor include path options place your project header path prior to the system header paths.
llasram
Was that so stupid an issue? Yes it was. Thank you :-)
klez
To avoid future problems, is there a quick reference for standard C header names?
klez
@klez That appears to be an existing question: http://stackoverflow.com/questions/2027991/list-of-standard-header-files-in-c-and-c . In this case though, the standards-related lists wouldn't have helped, because `memory.h` isn't a standard header. You can always see what your particular OS provides with something like `find /usr/include/ -type f -name '*.h'`.
llasram
@llasram: Provided, of course, that your particular OS has `find`, and keeps headers in `/usr/include/`. Not all people are lucky enough to run such OSes.
David Thornley
A: 

hmmmm...compiles for me...could it be an include path issue, with the wrong version of memory.h?

paquetp