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))
@Binkle Crashes with SIGABRT
@Binkle That's a typo
@Binkle On malloc
@Binkle malloc.c:2379: sysmalloc: Assertion `(old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)' failed.
@ademan @Binkle Sorry, no, it's a school project, but I think I found the issue.
I'm getting the wrong sizeof because I'm stupid and typed in the wrong struct.
void symtable_init(symtable_t **table){
(*table) = (symtable_t *)malloc(sizeof (symtable_item_t));
for(int i = 0; i < TABLE_SIZE; i++){
(**table)[i] = NULL;
}
}
If it’s crashing on malloc that sounds like it’s not properly linked tbh. Do you have access to a debugger?
How are you building and running it?
@ademan I do. That's how I know it's that line
What output do you get if you put this line before your malloc call?
printf("malloc = %p\n", malloc);
@matrix (alternatively, use your debugger to inspect the actual function address, if you know how, I figured this was an easier route though hah)
Token_type is just an enum