In C if I have
typedef struct
{
Token_type type;
Token_data data;
} Token_t;
typedef struct sitem {
char *key;
struct Token_t *token;
} item_t;
Why can't I do?
void insert(char *key, Token_t *data) {
item_t* new_item = malloc(sizeof (_item_t));
new_item->token = data;
}
@apropos Oh thanks, that was my problem
What do you mean you can’t do it?
There’s a couple of minor errors but I’m not sure if that’s what you’re getting at.
struct Token_t is distinct from Token_t might be the more subtle error, in case that’s what you’re after.
Consider your item_t
typedef struct sitem { ... } item_t;
struct sitem and item_t are equivalent, but struct item_t would be something else.
@matrix
So you're initializing the item_t new_item, and giving it memory, but you're not initializing the Token_t token within it and expect it to directly pass to it a different memory allocation?
@matrix
Man, I really hate C's pointer stuff...
One problem might be that you need to do new_item->token = *data