cliststructoperating-system

Error in c code: expected identifier or ‘(’ before ‘free_node_t’


.h file with header for creating a list in c:

 #ifndef SO605_GC
 #define SO605_GC
 #include <stddef.h>

 #define MEMSIZE 4096*1024*1024          

 typedef struct free_node {
     size_t size;
     struct free_node *next;
 } free_node_t;

 typedef *free_node_t mem_free_t;

 void *aloca(size_t size);
 void libera(void *ptr);

 #endif

When I compile the error occurs:

aloca.h:14:10: error: expected identifier or ‘(’ before ‘free_node_t’ typedef *free_node_t mem_free_t;

How to solve this?


Solution

  • You have a syntax error in

    typedef *free_node_t mem_free_t;
    

    which should be

    typedef free_node_t *mem_free_t;
    

    but please do not typedef pointers. Also I believe that the suffix _t is typically reserved.

    Note too that 4096*1024*1024 will not fit a 32-bit variable, whatever it is for, and probably will not multiply as you think it will.