日期:2014-05-16  浏览次数:20798 次

这个段错误,是什么原因?
typedef struct ringlink_operations
{
void *(*ringlink_malloc)(unsigned int size);
void (*ringlink_free)(void *dest);
void (*ringlink_memset)(void *dest, int value, unsigned int size);
void (*ringlink_memcpy)(void *dest, void *src, unsigned int size);
}ringlink_operations_t;

typedef struct ringlink
{
ringlink_operations_t *operations;
ringlink_mem_t *head;
ringlink_mem_t *read; /*Current position of read pointer.*/
ringlink_mem_t *write; /*Current position of read pointer.*/
ringlink_param_t param;
ringlink_status_t status;
}ringlink_t;

int ringlink_create(ringlink_t *ringlink, ringlink_operations_t *operations, ringlink_param_t *param)
{
int i;
ringlink_mem_t *temp;

RINGLINK_DBUG_LINE;
if((NULL==operations->ringlink_malloc) || 
(NULL==operations->ringlink_free) ||
(NULL==operations->ringlink_memcpy) ||
(NULL==operations->ringlink_memset))
{
RINGLINK_DBUG_LINE;
return -1;
}

RINGLINK_DBUG_LINE;
ringlink->operations = operations;

operations->ringlink_memcpy((char*)(&ringlink->param), (char*)param, sizeof(ringlink_param_t)); //这句正常
ringlink->operations->ringlink_memcpy((char*)(&ringlink->param), (char*)param, sizeof(ringlink_param_t));
       .........
}

static ringlink_operations_t userspace_operatioins = 
{
.ringlink_malloc = malloc,
.ringlink_free = free,
.ringlink_memset = memset,
.ringlink_memcpy = ringlik_memcpy,
};

ringlink_t tx;
int main()
{
int ret;

ringlink_param_t param;
param.key_size = 4;
param.value_size = 20;
param.total_count = 5;
param.overwrite_enable = 1;

ret = ringlink_create(&tx, &userspace_operatioins, &param); //这个函数里出错
printf("%s, %d ret=%d\n", __FUNCTION__, __LINE__, ret);

ringlink_show(&tx);

return 0;
}
段错误