Using ’0’ instead of ’NULL’
-
Hi everyone !
I'd like to know why Qt intend to uses 0 instead of NULL (null pointer).
Seen in Qt Documentation, example : QWidget::QWidget ( QWidget * parent = 0, Qt::WindowFlags f = 0 ) (http://doc.qt.nokia.com/4.6/qwidget.html).
Does Qt headers define NULL as 0 ?
Some code/dev rules are imposed in my company. So, can I use NULL instead of 0 (ex : QWidget::QWidget ( QWidget * parent = NULL, Qt::WindowFlags f = NULL ) ) or is it risky?
Regards,
Niak74 -
bq. Bjarne Stroustrup: In C++, the definition of NULL is 0
"Bjarne Stroustrup's C++ Style and Technique FAQ":http://www2.research.att.com/~bs/bs_faq2.html#null
-
0 is always 0, it can never be redefined as anything else.
-
In C, NULL is preferred because depending on the system, it might not be defined as 0 (but I've never seen an example of this). In C++, NULL is defined as 0 in the standard, so both are safely interchangeable. Some people still like using NULL because in their opinion it makes the code clearer. As previous posters have said, it's up to the coder.
-
-
"good article":http://mina86.com/2010/10/24/0-is-ambiguous/ about 0/NULL (and nullptr) in C/C++
-
There are a lot of companies banning the use of defines and macros just because of the possible risk of breaking a lot of stuff by changing just one define/macro. Since NULL is no more than 0 and not (void*)0 as it sometimes is in C, and it therefore will not generate compiler errors when used inappropriately, I see little value in typing it out.
-
-
[quote author="maciek" date="1291899880"]"good article":http://mina86.com/2010/10/24/0-is-ambiguous/ about 0/NULL (and nullptr) in C/C++[/quote] Thanks for the tipp, was interesting to read.