Now I don't understand why malloc isn't working

typedef union
{
int64_t int_d;
double number_d;
} Token_data;

typedef struct
{
Token_type type;
Token_data data;
} Token_t;

Token_t *my_token = (Token*) malloc(sizeof(Token_t))

@matrix is the "(Token*)" cast a typo on the post or is that direct from your code? I would expect that to not compile though so I doubt that's the issue
Follow

@Binkle @matrix The pointer gets casted to Token_t* when it's actually assigned anyway. You can do something like
int* c = (float*) malloc(sizeof(int));
*c = 1;
printf("%d", *c);
And it will just print a warning and that's it

· · Web · 0 · 0 · 1
Sign in to participate in the conversation
Game Liberty Mastodon

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