我正在尝试创建一个例程来在一个reagular队列中插入一个struct的值,但是,插入是基于优先级的。 出于某种原因,我在算法中遇到了SIGSEV错误。这是代码和结构声明。
void p_queue_insertion(Queue *f, int cpf_c, int cpf_t, char opr, int priority) {
int i = 0;
for(i = 0; i < f->size; i++) //f is a pointer to a dynamically
{ //alocated array of queues.
if(f[i].pri == priority);
{
Block* new_client = (Block*) malloc(sizeof(Block));
if(f != NULL)
{
f[i].size++;
new_client->c->cpf_client = cpf_c;
new_client->c->cpf_terceiros = cpf_t;
new_client->c->op = opr;
new_client->c->pri = priority;
new_client->next = NULL;
if(f[i].start == NULL)
f[i].start = new_client;
else
f[i].start->next = new_client;
f[i].end = new_client;
return;
}
}
}
}
在这种情况下,队列正在实现为链表,如下所示:
typedef struct queue
{
Block *start, *end;
int size;
int pr; //pr = priority of the queue.
} Queue;
struct“Block”声明为:
typedef struct block
{
Client* c;
struct block* next;
} Block;
最后,struct Client被声明为:
typedef struct client
{
int cpf_client, cpf_terceiros, pri; //pri = priority of the client.
char op;
} Client;
这是调试器返回的信息,它还突出显示了“new_client-&gt; c-&gt; cpf_client = cpf_c;”
的行。 0x0000000000401d0a <+154>: mov 0x18(%rbp),%edx
=> 0x0000000000401d0d <+157>: mov %edx,(%rax)
0x0000000000401d0f <+159>: mov -0x10(%rbp),%rax
如果这只是一个简单的愚蠢错误我提前道歉,但我真的很难用这个。提前谢谢。