Why can't the client dereference the pointer in this situation?

I understand that the client can manipulate the struct pointer in this situation, but cannot dereference it. I was wondering why exactly this is impossible to parse?

stack.h

#ifndef STACK_INCLUDED
#define STACK_INCLUDED

typedef struct Stack_T *Stack_T;

extern Stack_T stack_new(void);
extern int stack_empty( Stack_T p_stk );
extern void stack_push( Stack_T p_stk, void *p_data );
extern void *stack_pop( Stack_T p_stk );
extern void stack_free( Stack_T *p_stk );

#endif

      

stack.c

#include "stack.h"

struct Stack_T {
    int node_count;
    struct node {
        void *p_data;
        struct elem *p_link;
    } *p_head;
};

      

main.c

#include "stack.h"

int main(void)
{
    Stack_T stk;
    ...
    return EXIT_SUCCESS;
}

      

To be more precise why this object cannot be dereferenced basically

+3


source to share


1 answer


I am assuming "client" means "source file that includes stack.h

".

This is because struct Stack_T

it is not actually defined in the file stack.h

. He stated that he typedef

will ensure that the compiler understands that it will be defined somewhere struct Stack_T

, but not yet.



stack.c

is the only module that needs to know what is inside struct Stack_T

, so the structure definition is inside that file.

The clients of this code don't need to know what's inside struct Stack_T

, so they don't see the definition.

+3


source







All Articles