Something like assert() while define NDEBUG, but not abort()

Discussion in 'C Programming' started by Alex Vinokur, Jan 7, 2009.

  1. Alex Vinokur

    Alex Vinokur Guest

    Hi,

    From man abort() on HP-UX

    -------------------------------
    abort() first closes all open files, streams, directory streams, and
    message catalogue descriptors,
    ------------------------------

    1. Does assert() have the same behavior?

    2. If assert() doesn't close all open files, streams, directory
    streams etc,
    is there any possibility to cause assert()-like behavior in case
    that NDEBUG defined?


    Alex Vinokur
     
    Alex Vinokur, Jan 7, 2009
    #1
    1. Advertising

  2. Alex Vinokur

    Guest

    On 7 Jan, 09:10, Alex Vinokur <> wrote:

    > From man abort() on HP-UX
    >
    > -------------------------------
    > abort() first closes all open files, streams, directory streams, and
    >       message catalogue descriptors,
    > ------------------------------
    >
    > 1. Does assert() have the same behavior?


    assert() calls abort() (I checked the standard)


    > 2. If assert() doesn't close all open files, streams, directory
    > streams etc,
    >     is there  any possibility to cause assert()-like behavior in case
    > that  NDEBUG defined?


    mu

    --
    Nick Keighley
     
    , Jan 7, 2009
    #2
    1. Advertising

  3. Alex Vinokur

    Eric Sosman Guest

    Alex Vinokur wrote:
    > Hi,
    >
    > From man abort() on HP-UX
    >
    > -------------------------------
    > abort() first closes all open files, streams, directory streams, and
    > message catalogue descriptors,
    > ------------------------------


    This is (presumably) true of the abort() on HP-UX, but
    is not necessarily true of all abort() implementations on
    all systems. 7.20.4.1p2: "[...] Whether open streams with
    unwritten buffered data are flushed, open streams are closed,
    or temporary files are removed is implementation-defined. [...]"

    > 1. Does assert() have the same behavior?


    See Nick Keighley's response.

    > 2. If assert() doesn't close all open files, streams, directory
    > streams etc,
    > is there any possibility to cause assert()-like behavior in case
    > that NDEBUG defined?


    Since assert() calls abort() and abort() calls (or does
    the equivalent of) raise(SIGABRT), you could try installing a
    handler for SIGABRT and do your cleanup in the signal handler.
    But on a system where abort() doesn't clean up anyhow there's
    likely to be a good reason, and that reason (whatever it is)
    may also get in the way of your signal handler's efforts.

    --
    Eric Sosman
    lid
     
    Eric Sosman, Jan 7, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Robert Brewer
    Replies:
    1
    Views:
    519
    bsmith
    Nov 7, 2004
  2. Alex Vinokur

    assert(x) and '#define ASSERT(x) assert(x)'

    Alex Vinokur, Nov 25, 2004, in forum: C Programming
    Replies:
    5
    Views:
    960
    Keith Thompson
    Nov 25, 2004
  3. David
    Replies:
    11
    Views:
    664
    David
    Nov 8, 2005
  4. pereges

    NDEBUG and assert macros.

    pereges, Aug 1, 2008, in forum: C Programming
    Replies:
    5
    Views:
    5,512
    santosh
    Aug 2, 2008
  5. ImpalerCore

    To assert or not to assert...

    ImpalerCore, Apr 27, 2010, in forum: C Programming
    Replies:
    79
    Views:
    1,755
    Richard Bos
    May 17, 2010
Loading...

Share This Page