Похожие чаты

Why can i accessed to to the pointed-value *p after

free the memory ? it is true that the returned value is 0 but I tell myself that I will have either a compilation error or a runtime error.

5 ответов

10 просмотров

After the delete expression, the pointer becomes invalid. According to the C++ standard access of such a pointer is implementation defined (a type of undefined behaviour). Some platforms may give you segfault, some might not. It is not true. Delete doesn't set the pointer to null.

Issa N'golo-Coulibaly Автор вопроса
Manav | avoid unnecessary messaging me
After the delete expression, the pointer becomes i...

but it's a memory safety issue, isn't it? is there a proper way to handle this case and the pointer is invalid right after using the delete expression

Issa N'golo Coulibaly
but it's a memory safety issue, isn't it? is there...

It is. There are two ways to go about it, 1. hide it with RAII or 2. set the pointer to null after you delete so subsequent deletes don't do anything plus your pointer is now null so trying to dereference it it will give you errors.

Issa N'golo-Coulibaly Автор вопроса
Manav | avoid unnecessary messaging me
It is. There are two ways to go about it, 1. hide ...

thank you very much. i understand the second point. i will googling what's RAII because i don't know what it is. 🙂

Похожие вопросы

Обсуждают сегодня

Hi everyone! I have a two-folded message to share today. First: updates and news, as we are being asked for those. We still want to go like we did the last 6 years: we w...
Marten | Unibright.io
31
Интересно, нет ли какого-то способа получить из dll не адрес самой метки, а адрес со смещением?
The Bird of Hermes
54
generic procedure function test<T>(param: T); type case T of longint: NewT = word; longword: NewT = byte; end; var v1: NewT; Как это можно сделать? Чтобы у меня...
notme
21
Guys, mexc or gate.io (only exchanges with the token I need, unfortunately): depositing xmr, not withdrawing, is safe rn, or can fall for shotgun kyc? (I heard gate is alread...
another one bites the dust
18
Whoa, did you guys see this FUNToken Seed Grant announcement? 💸
Noah Noure
37
Делал задачу вот такую https://stepik.org/lesson/4985/step/9?unit=1083 получилось такое https://play.haskell.org/saved/ipKrepqe оно работает, тестов много не писал, но работае...
Fedor
22
hello guys, I have a laptop, if you connect wired headphones, the sound will come from the headphones and the built-in speakers AT THE SAME TIME. How can I make the sound com...
El Pepe
21
hello, does someone have a good cheat sheet (max 2 sides of A4 paper sheet) for C only? I need it to cover most useful function for math, dynamic memory, strings, files (I/O),...
狐 - えんきどぅ
19
Всем привет, все время юзал бандлы, но появилась задача по базовому образу и команда werf build не пушит образ werf build --config='./root/werf.yaml' --repo ${CI_REGISTRY_IMAG...
Илья Корж
4
А можно как-нибудь включить default'ные настройки ядра?
Ari
26
Карта сайта