How to check Type of structure in C -


i made simple listing struct in c holds kind of data using void* pointer, like:

struct node { void *the_data; node *next; }; 

it working fine, have lists contains, example, struct_a in list , struct_b in list. need check if first element of list of struct_a type or struct_b type in single if() question know data list holding. how this? thanks

edit:

i've come simple solution enough problem now, dunno if it's best:

struct node { void *data; node *next; } 

and added "descriptor" node, contains address of first node , info type:

struct list_desc { node *list; short int type; } 

and i'll use macros like

#define __data_type1 10 #define __data_type2 20 

so later can compare if( struct.type == __data_tipe1 ) etc...

what think that:

typedef enum tag_elementtype {     elementa,     elementb } en_elementtype;  typedef struct tag_container {     en_elementtype elementtype;     void *pdata; } st_container; 

in case structure this:

typedef struct tag_node {     st_container the_data;     struct tag_node *next; } st_node; 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -