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 9166199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:06:08+00:00 2026-06-17T15:06:08+00:00

Upgrading some legacy code, I’ve started getting warning: passing NULL to non-pointer argument 1

  • 0

Upgrading some legacy code, I’ve started getting “warning: passing NULL to non-pointer argument 1 of ‘Identifier::Identifier(int)’ [-Wconversion-null]” messages from g++. Mostly this is good, but it doesn’t seem to take classes with multiple constructors into account.

For example, take this test code:

#include <stdio.h>

class Identifier
{
  private:
    int m_iID;

  public:
    Identifier(const char* p_c) { m_iID = p_c ? p_c[0] : 0; }
    Identifier(int i) { m_iID = i; }
};

int main(int argc, char* argv[])
{
  Identifier* p_ID = new Identifier(NULL);

  return 0;
}

(Please ignore what the constructors actually do, this is just an illustration of the issue. For context, the code in question is a class that stores an identifier in the form of a hash value. The constructors can either take a string to convert to a hash, or the hash value directly.)

The “new” statement on the third to last line throws this warning. The thing that is puzzling me is that g++ is apparently assuming that it needs to use the Identifier(int i) constructor, and ignores the Identifier(const char* p_c) constructor, which is a pointer.

Note that changing the ints to unsigned ints causes an ambiguity error instead, this being a 32-bit system.

I know specifying -Wno-conversion-null would fix the problem, as would passing 0 or explicitly casting NULL to const char*. But I’m curious as to why the seemingly valid constructor is being ignored. Plus, I’d like to avoid a massive search-and-replace job whilst keeping the warning active.

  • 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-17T15:06:09+00:00Added an answer on June 17, 2026 at 3:06 pm

    At least on this CentOS box, NULL is defined in linux/stddef.h:

    #undef NULL
    #if defined(__cplusplus)
    #define NULL 0
    #else
    #define NULL ((void *)0)
    #endif
    

    As such, NULL in C++ is an integer; therefore the compiler chooses the int constructor by default and gives you the warning you’re seeing.

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

Sidebar

Related Questions

I have encountered a weird situation while updating/upgrading some legacy code. I have a
I'm debugging and upgrading some legacy PHP and JavaScript code and I've found some
I've recently started upgrading some applications to use Spring Webflow 2, and I want
I'm upgrading some code written for Google Maps API v2, and I wish to
I have inherited some really old VC6.0 code that I am upgrading to VS2008
This is about a legacy Access 2003 database that I've inherited. There's some code
I am having some trouble getting py27-scipy to build & install after upgrading to
I'm upgrading some ancient (from 2003) Delphi code to Delphi Architect XE and I'm
Ok, so we're upgrading a client's legacy code from 2.0.2 to latest rails. Most
I am upgrading some legacy 3rd party components from Delphi 6 source up to

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.