I have 2 simple structs and one has array of the second one.
When accesing the second one my program crashes in visual studio but not in codeblocks.
So one line is not working and another one is.
Can somebody explain why?
struct buffer {
uint64_t size;
void* data;
};
struct list_of_buffers {
uint64_t number_of_buffers;
bool* active_buffers;
struct buffer* array_of_buffers;
}buffer_list;
void alloc_fun(int size){
buffer_list.array_of_buffers = (struct buffer*)calloc(0, sizeof(struct buffer) * size);
//this one makes my program crash
buffer_list.array_of_buffers[0].data = NULL;
//this one doesnt
struct buffer tmp = buffer_list.array_of_buffers[0];
tmp.data = NULL;
}
Can somebody explain please?
buffer_list.array_of_buffersidiscalloc(0,means you allocate space for 0 elements - which is still 0 (and you are therefore not allowed to access any element viabuffer_list.array_of_buffers[x])