我有这个包含文件(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 */
Run Code Online (Sandbox Code Playgroud)
而这个实现文件(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
Run Code Online (Sandbox Code Playgroud)
当我尝试编译时,memory.c我得到每个函数定义的这个错误
src/memory.c:5:错误:预期')'在'*'标记之前
其中第5行是函数定义 memory_init()
有人可以告诉我为什么我收到此错误?
lla*_*ram 15
因为系统memory.h正在遮蔽你memory.h,导致#include成功而不会声明你的类型.几个可能的修复:
#include <myproj/memory.h>)包含您的文件.#include包装的文件名的优先规则"生效.| 归档时间: |
|
| 查看次数: |
78064 次 |
| 最近记录: |