Thread: Library Implementation of nullptr

  1. #1
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003

    Library Implementation of nullptr

    I have been looking at a library implementation of nullptr as shown in A name for the null pointer: nullptr (revision 2) (warning: PDF).

    One criticism leveled against it is that:
    Experiments with several popular existing compilers show that it generates poor and/or misleading compiler diagnostics for several of the common use cases described in section 2. (Examples include: "no conversion from 'const' to 'int'"; "no suitable conversion function from 'const class <unnamed>' to 'int' exists"; "a template argument may not reference an unnamed type"; "no operator '==' matches these operands, operand types are: int == const class <unnamed>".) We believe that compilers will still need to add special knowledge of nullptr in order to provide quality diagnostics for common use cases.
    It seems to be that this can be solved simply by naming the class, e.g., nullptr_t. This allows one to create more nullptr_t objects other than nullptr, but since they are all equivalent anyway, it seemes a small price to pay for far more readable error messages. What other problems do you see with turning this anonymous class into the nullptr_t class?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    You lose the second part of this design goal:
    The null pointer is a value that has no nameable type, and its type cannot be deduced as a template argument.
    I don't see the nullptr proposal as even remotely difficult to implement for compilers - GCC already has most of it - so I think the keyword solution is simply preferable.
    All the buzzt!

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Global variable in shared library
    By krock923 in forum C Programming
    Replies: 5
    Last Post: 01-11-2008, 04:56 PM
  2. my free c++ library
    By jinhao in forum A Brief History of
    Replies: 0
    Last Post: 11-01-2007, 10:00 PM
  3. C++ Library Design
    By CornedBee in forum C++ Programming
    Replies: 2
    Last Post: 09-30-2004, 10:40 AM
  4. .lib vs .h vs .dll
    By Shadow12345 in forum C++ Programming
    Replies: 13
    Last Post: 01-01-2003, 05:29 AM
  5. Replies: 4
    Last Post: 11-12-2002, 06:26 AM