Results 1 to 7 of 7

Thread: Pointers: NULL vs. 0

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    Join Date
    Jan 2010
    Location
    Perth, Australia
    Posts
    37
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 2 Times in 2 Posts

    Default Re: Pointers: NULL vs. 0

    Quote Originally Posted by wysota View Post
    You shouldn't (or at least needn't) use NULL in C++ code. NULL is a C macro while C++ has "null" and "0" defined, you should use either of them.
    I tried to compile
    Qt Code:
    1. int *p = null;
    To copy to clipboard, switch view to plain text mode 
    but g++ reported "error: 'null' was not in this scope". Do I need to #include something?

    Also, I was directed to Bjarne Stroustrup's (creator of C++) website at http://www2.research.att.com/~bs/bs_faq2.html#null where he said "In C++, the definition of NULL is 0, so there is only an aesthetic difference. I prefer to avoid macros, so I use 0" which sounds like NULL is ok in C++...?

    Sorry for posting in the wrong forum; I thought it was Qt thing instead of a C++ thing.

  2. The following user says thank you to hackerNovitiate for this useful post:

    genomega (1st February 2010)

Similar Threads

  1. setRelation and NULL in ID
    By Auryn in forum Qt Programming
    Replies: 4
    Last Post: 26th May 2015, 17:20
  2. Null for QDateEdit
    By wirasto in forum Qt Programming
    Replies: 1
    Last Post: 16th November 2009, 22:54
  3. QPixmap seems to be null but it isn't
    By satoshi in forum Qt Programming
    Replies: 7
    Last Post: 8th May 2009, 10:23
  4. QSqlTableModel and NULL
    By karas in forum Qt Programming
    Replies: 0
    Last Post: 9th February 2009, 13:55
  5. checking for null
    By drkbkr in forum General Programming
    Replies: 6
    Last Post: 13th March 2006, 22:54

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.