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

  • Home
  • SEARCH
  • 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 8897233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:17:13+00:00 2026-06-15T00:17:13+00:00

I came across a small standard header file <new> . I have probably not

  • 0

I came across a small standard header file <new>. I have probably not seen its direct use before. Here is the g++ version for those who are interested.

Below part is of my interest:

  struct nothrow_t { };
  extern const nothrow_t nothrow;
  /** If you write your own error handler to be called by @c new, it must
   *  be of this type.  */
  typedef void (*new_handler)();
  /// Takes a replacement handler as the argument, returns the previous handler.
  new_handler set_new_handler(new_handler) throw();
  1. How struct nothrow_t and its object nothrow are used by programmers ? Is the
    object really needed to be extern?
  2. When does new_handler used ?
  3. Why all the operator new/delete are declared in extern C++ block ?
  • 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-15T00:17:15+00:00Added an answer on June 15, 2026 at 12:17 am

    nothrow_t is used to tell operator new to operate in the backwards-compatible “return null on failure rather than throwing an exception” mode.

    That is, if you see code like this:

    int * idx = new(std::nothrow) int;
    

    that would be nothrow_t at work. For the relevant sections in the standard start at (as of C++11 N3376) 17.6.4.6 [replacement.functions]/1 and work your way down from there.

    To answer your specific questions:

    1. Yes, it really does have to be extern, at least according to 18.6 [support.dynamic]/1, which includes:

      namespace std {
          class bad_alloc;
          class bad_array_new_length;
          struct nothrow_t {};
          extern const nothrow_t nothrow;
          typedef void (*new_handler)();
          new_handler get_new_handler() noexcept;
          new_handler set_new_handler(new_handler new_p) noexcept;
      }
      

      Moreover, 17.6.2.3 [using.linkage]/1 says “Entities in the C++ standard library have external linkage (3.5)”. Functions and classes (e.g. get_new_handler and set_new_handler above) don’t explicitly need to be annotated to have external linkage because they have external linkage by default.

    2. new_handler is used when the user overrides the default operator new in use by calling set_new_handler. It is just a function pointer type.

    3. Probably because the signatures for operator new are not reserved in C. extern "C++" tells the compiler that it is allowed to do name mangling and other C++ specific things to those functions. This way you can compile one translation unit as C, and one as C++, and link them together in the same binary without worrying that someone in C land defined a function conflicting with the compiler’s operator new.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I came across an interesting situation today: I have a small app with a
I came across a situation where I have a pretty big file that I
In a small project of mine I've came across the need of a collapsible
Came across this code: <?php require_once 'HTTP/Session/Container/DB.php'; $s = new HTTP_Session_Container_DB('mysql://user:password@localhost/db'); ini_get('session.auto_start') or session_start();
I recent came across Javascript templates and have become quite intrigued. I am building
I'm building something similar to a Blogfarm and I came across a small hurdle.
I recently came across classes that use a configuration object instead of the usual
While testing a new application, we came across an issue that sometimes a stored
While testing a program for scalability, I came across the situation where I have
i'm working on extjs and came across one small problem it is , wen

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.