C 队列:警告:赋值从整数生成指针而不进行强制转换

C 队列:警告:赋值从整数生成指针而不进行强制转换,c,queue,C,Queue,我在main.c中有代码: #include <stdio.h> #include "queue.h" int main() { Queue Q = CreateQueue(); /* other code */ return 0; } 函数CreateQueue()位于文件queue.c中: #include <stdio.h> #include <stdlib.h> #include "queue.h" // CREATE T

我在main.c中有代码:

#include <stdio.h>
#include "queue.h"

int main() {
    Queue Q = CreateQueue();
    /* other code */
    return 0;
}
函数
CreateQueue()
位于文件
queue.c
中:

#include <stdio.h>
#include <stdlib.h>
#include "queue.h"

// CREATE THE QUEUE
Queue CreateQueue() {
    Queue Q = malloc(sizeof(struct QueueRecord));
    Q->Array = malloc(sizeof(int*) * MAX_SIZE);
    InitQueue(Q);
    return Q; /* Above goes right except cannot return the pointer. */
}

// INIT THE QUEUE
void InitQueue(Queue Q) {
    Q->Front = -1;
    Q->Rear = -1;
} /* this function does not make an error I think */

谢谢。

您的声明中有一个输入错误:您声明了“CreateQueue”而不是“CreateQueue”。C默认为CreateQueue的int返回类型,这可能是导致您出现问题的原因。

该错误意味着您正在执行以下操作:
int value=10;int*value\u ptr=value
而不是
int*value\u ptr=&value
。但它看起来不在那个块中,
InitQueue
做什么呢?在哪一行可以得到“不带强制转换的整数指针”?您是用
-Wall-Wextra-Werror
编译的吗?如果不是,您应该是。在
队列Q=CreateQueue()中使用它之前,您是否声明了
CreateQueue()
因为如果您没有,编译器将假定它返回一个
int
(除非您在严格的C99或C11模式下编译),然后触发主题行中的投诉。这可能需要一个明确的说明。另外,您还有
#ifndef queue_h
,但没有相应的
#define _queue_h
,如果该标题在同一翻译单元中两次获得
#include
d,则会导致问题。
#include <stdio.h>
#include <stdlib.h>
#include "queue.h"

// CREATE THE QUEUE
Queue CreateQueue() {
    Queue Q = malloc(sizeof(struct QueueRecord));
    Q->Array = malloc(sizeof(int*) * MAX_SIZE);
    InitQueue(Q);
    return Q; /* Above goes right except cannot return the pointer. */
}

// INIT THE QUEUE
void InitQueue(Queue Q) {
    Q->Front = -1;
    Q->Rear = -1;
} /* this function does not make an error I think */
double free or corruption (out): 0x00619270