Warning: dereferencing void * pointer

I am doing my homework and I was wondering if anyone can help me figure out what the error means "warning: dereferencing" void * pointer "means link to my code. Thank you so much.

Error warning:

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



#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)
    *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;



#include "globals.h"



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);




#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)




source to share

1 answer

has a type void*

, so it must be

`DATA(*plst) = data;`
`NEXT(*plst) = NULL;`


you cannot dereference the void * pointer you need to return it to type node if you want to access the node structure. Read the void pointer to get a better understanding



All Articles