【发布时间】:2010-09-15 17:11:43
【问题描述】:
我有这个包含文件 (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: 错误:在 '*' 标记之前需要 ')'
第 5 行是memory_init() 的函数定义
谁能告诉我为什么会出现这个错误?
【问题讨论】:
-
在 OSX Snow Leopard 上的 gcc 版本 4.2.1,带有 -ansi 开关
-
在您的标头被包含之前,也许其他一些标头已经定义了 MEMORY_H?
标签: c