Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8020723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:46:06+00:00 2026-06-04T21:46:06+00:00

I am working on a library with two different end users one of which

  • 0

I am working on a library with two different end users one of which is using gcc 4.5.3 and the other just moved to gcc 4.6.3. The library uses the new C++11 smart pointers (in particular unique_ptr) and compiles fine on gcc 4.5.3. However, between those two versions gcc began supporting nullptr so the API of unique_ptr changed to match the standard more closely. In doing so now the following code went from fine to ambiguous

unique_ptr up( new int( 30 ) );
...
if( up == 0 ) // ambiguous call now to unique_ptr(int) for 0

Is there a clean (viz., next sentence) way to change the if statement above so that it works both with and without nullptr? I’d like to avoid a configure check and then a macro like the following (which I think will work) if possible

#if defined NULLPOINTER_AVAILABLE
  #define NULLPTR (nullptr)
#else
  #define NULLPTR (0)
#endif

or is this the only way to get the behavior I am looking?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T21:46:07+00:00Added an answer on June 4, 2026 at 9:46 pm

    What errors did you hit?

    #include <iostream>
    #include <memory>
    int main() {
     using namespace std;
     unique_ptr<int> up( new int( 30 ) );
     if (up == 0)
         cout << "nullptr!\n";
     else cout << "bam!\n";
    }
    

    compiles fine with with g++ -std=c++0x -Wall nullptr.cpp -o nullptr (gcc 4.6.2).

    Also, go through N2431 paper by Stroustrup and Sutter on nullptrwhere a similar usage (comparison with 0) is explicitly listed in one of the examples.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a library that allows its users (other libraries residing in
I'm working using scriptaculous library. However I'm facing some issues with inclusion of the
I'm working on a website which takes payment from a customer. I'm using Kohana
I'm working on a small game geometry library, and among a bunch of other
We are working on an Asp.net project. It has two parts, first one is
I am trying to synchronize two thread (working on the same C++ map) using
We are working on integrating two different applications that run simultaneously and share data.
I'm using two different libraries in my project, and both of them supply a
I'm working with an unmanaged library through P/Invoke and it uses three structs (although
I have two projects, a Cocoa iPhone application and a static library which it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.