我正在做功課,我想知道是否有人可以幫助我找出錯誤「警告:解除引用」void *'指針「是指引用我的代碼。非常感謝你。警告:解除引用'void *'指針
錯誤警告:
circular_list.c: In function ‘allocate_node’:
circular_list.c:36(line: DATA(lst) = data;): warning: dereferencing ‘void *’ pointer
circular_list.c:36(line: DATA(lst) = data;): error: request for member ‘datapointer’ in something not a structure or union
circular_list.c:37(line: NEXT(lst) = NULL;): warning: dereferencing ‘void *’ pointer
circular_list.c:37(line: NEXT(lst) = NULL;): error: request for member ‘next’ in something not a structure or union
circular_list.c
#include <stdio.h>
#include <stdlib.h>
#include "globals.h"
#include "circular_list.h"
typedef struct node *list_rep;
typedef struct node {
generic_ptr datapointer;
list_rep next;
} node;
#define DATA(lst) ((lst)->datapointer)
#define NEXT(lst) ((lst)->next)
#define TOLIST(list_rep) ((list) (list_rep))
#define TOREP(lst) ((list_rep)(lst))
#define TOLISTPTR(list_rep_ptr) ((list *) (list_rep_ptr))
#define TOREPPTR(lst_ptr) ((list_rep *)(lst_ptr))
static status allocate_node (list_rep *p_lst, generic_ptr data)
{
list lst = (list) malloc(sizeof(node));
if (lst == NULL)
return ERROR;
*p_lst = lst;
DATA(lst) = data;
NEXT(lst) = NULL;
return OK;
}
static void free_node (list *p_lst)
{
free(*p_lst);
*p_lst = NULL;
extern status init_circ_list (list *p_lst)
{
*p_lst = NULL;
return OK;
}
extern bool empty_circ_list (list lst)
{
return (lst == NULL) ? TRUE : FALSE;
}
status circ_insert (list *p_lst, generic_ptr data)
{
list_rep lst, *p_lst_rep = TOREPPTR(p_lst);
if (allocate_node(&lst, data) == ERROR)
return ERROR;
if (empty_circ_list(*p_lst)) {
NEXT(lst) = lst;
*p_lst_rep = lst;
} else {
NEXT(lst) = NEXT(*p_lst_rep);
NEXT(*p_lst_rep) = lst;
}
return OK;
}
circular_list.h
#include "globals.h"
#ifndef _CIRCULAR_LIST_H
#define _CIRCULAR_LIST_H
ABSTRACT_TYPE(list);
extern status init_circ_list (list *p_lst);
extern bool empty_circ_list (list lst);
extern status circ_insert (list *p_lst, generic_ptr data);
extern status circ_append (list *p_lst, generic_ptr data);
extern status circ_delete (list *p_lst, generic_ptr *p_data);
extern status circ_delete_node(list *p_lst, list node);
extern generic_ptr circ_head(list lst);
extern list circ_tail(list lst);
#endif
globals.h
#ifndef _GLOBALS_H
#define _GLOBALS_H
typedef enum {OK, ERROR} status;
typedef enum {FALSE = 0, TRUE = 1} bool;
typedef void *generic_ptr;
typedef unsigned char byte;
#define ABSTRACT_TYPE(t)
typedef void *(t)
#endif
我敢打賭,答案隱藏在'ABSTRACT_TYPE'宏後面 - 那是什麼?我猜這裏面有一個'void *'。 – 2012-03-28 22:05:56
錯誤的行號與您發佈的代碼不匹配 – 2012-03-28 22:06:59
我只是修復了我在發佈後意識到它後遺憾大衛 – Cka91405 2012-03-28 22:09:12