我已經在這個問題上工作了大約一個星期,我查了很多「不兼容的指針類型」警告解決方案,但我仍然對如何解決這個編譯錯誤感到困惑。警告:不兼容的指針類型
我得到一個錯誤說:
char_stack_interface.c: In function ‘pop_char’:
char_stack_interface.c:32: warning: passing argument 2 of ‘pop’ from incompatible pointer type
char_stack_interface.c: In function ‘top_char’:
char_stack_interface.c:43: warning: passing argument 2 of ‘top’ from incompatible pointer type
這是我的代碼:
char_stack_interface.h:
#ifndef _CHAR_STACK_INTERFACE_H
#define _CHAR_STACK_INTERFACE_H
#include "stack.h"
extern status push_char(stack *p_s, char c);
extern status pop_char (stack *p_s, char *p_c);
extern status top_char (stack *p_s, char *p_c);
#endif
stack.h:
#ifndef _STACK_H
#define _STACK_H
#include "globals.h"
ABSTRACT_TYPE(stack);
extern status init_stack (stack *p_S);
extern bool empty_stack(stack *p_S);
extern status push (stack *p_S , generic_ptr data);
extern status pop (stack *p_S , generic_ptr *p_data);
extern status top (stack *p_S , generic_ptr *p_data);
#endif
char_stack_interface。 c:
#include <stdio.h>
#include <stdlib.h>
#include "char_stack_interface.h"
#include "stack.h"
status push_char(stack *p_s, char c)
{
char *p_c = NULL;
p_c = (char *) malloc(sizeof(char));
if (p_c == NULL)
return ERROR;
*p_c = c;
if (push(p_s, p_c) == ERROR) {
free(p_c);
return ERROR;
}
return OK;
}
status pop_char (stack *p_s, char *p_c)
{
char *p_data;
if (pop(p_s, p_data) == ERROR)
return ERROR;
*p_c = *p_data;
free(p_data);
return OK;
}
status top_char (stack *p_s, char *p_c)
{
char *p_data;
if (top(p_s, &p_data) == ERROR)
return ERROR;
*p_c = *p_data;
return OK;
}
您必須添加更多信息。更好地粘貼標題(或至少從那裏的主要類型定義)以及你得到警告的那一行。 – chetan 2012-02-17 16:55:02
我剛剛意識到像一個假人,我沒有把我的錯誤信息在那裏對不起,我剛剛更新它:) – Cka91405 2012-02-17 16:55:48
@ Cka91405:'流行'和'頂部'原型是什麼樣子? – netcoder 2012-02-17 16:58:43