Library Implementation of nullptr

This is a discussion on Library Implementation of nullptr within the C++ Programming forums, part of the General Programming Boards category; I have been looking at a library implementation of nullptr as shown in A name for the null pointer: nullptr ...

  1. #1
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,461

    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?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    Posts
    8,893
    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!
    CornedBee

    "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, 03:56 PM
  2. my free c++ library
    By jinhao in forum A Brief History of Cprogramming.com
    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, 04:29 AM
  5. Replies: 4
    Last Post: 11-12-2002, 05:26 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21