我有这个包括文件(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 */
而这个执行文件(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
当我尝试编译memory.c
我得到这个错误每个和每个函数的定义
src/memory.c:5: error: expected ')' before '*' token
其中第5行是memory_init()
的函数定义
有人可以告诉我为什么我得到这个错误吗?
什么编译器/平台? – abelenky 2010-09-15 17:16:34
OSX Snow Leopard上的gcc版本4.2.1,带有-ansi开关 – 2010-09-15 17:18:15
也许某些其他标题在包含标题之前已经定义了MEMORY_H? – Dirk 2010-09-15 17:18:44