Tôi có này bao gồm tập tin (memory .h
)lỗi: dự kiến ')' trước khi '*' thẻ
#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 */
Và tập tin thực hiện này (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
Khi tôi cố gắng biên dịch memory.c
tôi nhận được lỗi này cho mỗi và mọi định nghĩa chức năng
src/memory.c:5: error: expected ')' before '*' token
trong đó dòng 5 là định nghĩa hàm cho memory_init()
Ai đó có thể vui lòng cho tôi biết lý do tôi nhận được lỗi này?
trình biên dịch gì/nền tảng? – abelenky
gcc phiên bản 4.2.1 trên OSX Snow Leopard, có chuyển đổi -ansi –
Có thể một số Tiêu đề khác đã được định nghĩa MEMORY_H trước khi tiêu đề của bạn được bao gồm? – Dirk