on-internet
← Community

Deleting a buffer through a different type of pointer

Stack Overflow ·

Say I have the following C++ code: char *p = new char[cb]; SOME_STRUCT *pSS = (SOME_STRUCT *) p; delete pSS; Is this safe according to the C++ standard? Do I need to cast back to a char* and then use delete[]? I know it'll work in most C++ compilers, because it's plain-ordinary-data, without any destructors. Is it guaranteed to be safe?

Comments

Sign in or sign up to comment and upvote.

No comments yet.