c++ - I can't understand the deleteOwnedPtr function in Webkit -


in found function in webkit

template<typename t> inline void deleteownedptr(t* ptr) {     typedef char known[sizeof(t) ? 1 : -1];     if(sizeof(known))         delete ptr; } 

why don't use

if (sizeof(t))     delete ptr; 

what mean

char known[-1]; 

found explanation in webkit-dev mailing list. raises compiler errors if trying delete incomplete types.

https://lists.webkit.org/pipermail/webkit-dev/2010-november/015051.html

if delete pointer , object has incomplete type, undefined behavior. instead code causes compilation fail if object has incomplete type. use of negative number size of array way guarantee compilation error.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -