当前位置: 技术问答>linux和unix
编译出错
来源: 互联网 发布时间:2016-10-03
本文导语: 头文件 //fifo_buffer.h #include #include #include typedef struct _FIFO_BUFFER { unsigned char *buffer; unsigned int size; unsigned int write; unsigned int read; //spinlock_t *lock; }fifo_buffer; void init_fifo_buffer(fifo...
头文件
C文件
main函数
错误码:
fifo_buffer.c: 在函数‘init_fifo_buffer’中:
fifo_buffer.c:9: 错误: 在非结构或联合中请求成员‘buffer’
fifo_buffer.c:10: 错误: 在非结构或联合中请求成员‘size’
fifo_buffer.c:11: 错误: 在非结构或联合中请求成员‘write’
fifo_buffer.c:12: 错误: 在非结构或联合中请求成员‘read’
//fifo_buffer.h
#include
#include
#include
typedef struct _FIFO_BUFFER
{
unsigned char *buffer;
unsigned int size;
unsigned int write;
unsigned int read;
//spinlock_t *lock;
}fifo_buffer;
void init_fifo_buffer(fifo_buffer*, unsigned int);
C文件
//fifo_buffer.c
#include "fifo_buffer.h"
void init_fifo_buffer(fifo_buffer* p_buffer,unsigned int buffer_size)
{
p_buffer.buffer = (char*)malloc(buffer_size);
p_buffer.size = buffer_size;
p_buffer.write = 0;
p_buffer.read = 0;
}
main函数
#include "fifo_buffer.h"
int main()
{
return 0;
}
错误码:
fifo_buffer.c: 在函数‘init_fifo_buffer’中:
fifo_buffer.c:9: 错误: 在非结构或联合中请求成员‘buffer’
fifo_buffer.c:10: 错误: 在非结构或联合中请求成员‘size’
fifo_buffer.c:11: 错误: 在非结构或联合中请求成员‘write’
fifo_buffer.c:12: 错误: 在非结构或联合中请求成员‘read’
|
p_buffer 是指针啊!!
改成
p_buffer->buffer = (char*)malloc(buffer_size);
p_buffer->size = buffer_size;
p_buffer->write = 0;
p_buffer->read = 0;
改成
p_buffer->buffer = (char*)malloc(buffer_size);
p_buffer->size = buffer_size;
p_buffer->write = 0;
p_buffer->read = 0;
|
楼上正解。
像下面这样改。
像下面这样改。
#include "fifo_buffer.h"
void init_fifo_buffer(fifo_buffer* p_buffer,unsigned int buffer_size)
{
p_buffer->buffer = (char*)malloc(buffer_size);
p_buffer->size = buffer_size;
p_buffer->write = 0;
p_buffe->.read = 0;
}
|
可以按楼上的试试
|
楼上完全正解