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;

}

Follow

@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?

· · Web · 1 · 0 · 1

@matrix
Man, I really hate C's pointer stuff...
One problem might be that you need to do new_item->token = *data

Sign in to participate in the conversation
Game Liberty Mastodon

Mainly gaming/nerd instance for people who value free speech. Everyone is welcome.