And so, I have two functions, one allocates memory for the structure, the other frees. Well, since I want to avoid problems with the double release of memory, I decided to check the pointer for 'nullity' and reset it after release.
Less words, more code:
#define container_of(ptr, type, member) ((type *)((char *)(ptr) - offsetof(type, member))) using Tint = int64_t; using Tuint = uint64_t; using Pint = Tint *; struct Numx { Tuint alen; Tint len; bool sgn; Tint exp, m; Tuint d, reserved[12]; }; // выделяет память и возвращает указатель на 'm' Pint ALLOCX(Tuint len) { if (len == 0) { return nullptr; } Numx *ptr = (Numx *)operator new((len - 1) * sizeof(Tint) + sizeof(Numx)); ptr->alen = len; ptr->len = 0; ptr->sgn = 0; ptr->exp = 1; ptr->d = 1; return &ptr->m; } // через макрос container_of получает указатель на структуры и освобождает память void FREEX(Pint x) { if (x == nullptr) { return; } operator delete((void *)container_of(x, Numx, m)); x = nullptr; printf("%p\n", x); // <= выводит '0000000000000000' } int main() { Pint x = ALLOCX(1); printf("%p\n", x); // <= выводит '000000013F210060' FREEX(x); printf("%p\n", x); // <= опять '000000013F210060' std::cin.get(); return 0; } And so, what's the problem? Why does the FREEX () function print zeros, and right after it does not?