So, I'm trying to write a function which return a pointer to an ADT, in the heap.
The problem is that I can't manipulate it after the memory allocation. Here is a simplified code
typedef struct _entity {
int value;
} *Entity;
Entity *new_entity() {
Entity *ptr = (Entity*)malloc(sizeof(struct _entity));
assert( ptr );
(*ptr)->value = 5; // program crashes after this line
return ptr;
}
The error is:
Unhandled exception at 0x013e1665 in test.exe: 0xC0000005: Access violation writing location 0xcdcdce21.