I have here a really weird issue:
typedef struct s_mem_chunk { void *addr; unsigned int size; short is_alloc; struct s_mem_chunk *prev; } t_mem_chunk; #include <stdio.h> #include <stdlib.h> int main() { t_mem_chunk *mem_chunk; mem_chunk = malloc(sizeof(*mem_chunk)); mem_chunk->prev = 0; printf("%x + %x = %x\n", mem_chunk->prev, sizeof(*mem_chunk), mem_chunk->prev + sizeof(*mem_chunk)); return 0; } So the code here should output: "0 + 18 = 18" And it output instead "0 + 18 = 240"
So I am wondering why, this is may cause by the sizeof ot I dont know... I request your help, thanks in advance for your time and have a nice evening ! :D
sizeof(*mem_chunk)is a perfectly valid way to obtain the size of the type pointed to bymem_chunk.sizeof(t_mem_chunk) == 0x240/0x18 == 0x18 == 24.