assert()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dave

    assert()

    In a nutshell, what is the behavior of the assert() macro ***as proscribed
    by the C89 Standard*** (which I don't have)? Of course, it doens't appear
    in the C++ Standard since it's inherited from C. Hence my inquiry about the
    C Standard even though I care about this from a C++ perspective...

    Specifically, I'm wondering what the Standard has to say about when the
    compiler ignores asserts and when the compiler is to compile them in and
    generate code for them. After all, the Standard says nothing debug vs.
    release builds...


  • Simon Saunders

    #2
    Re: assert()

    On Wed, 19 Nov 2003 12:50:40 -0700, Dave wrote:
    [color=blue]
    > In a nutshell, what is the behavior of the assert() macro ***as
    > proscribed by the C89 Standard*** (which I don't have)? Of course, it
    > doens't appear in the C++ Standard since it's inherited from C. Hence
    > my inquiry about the C Standard even though I care about this from a C++
    > perspective...
    >
    > Specifically, I'm wondering what the Standard has to say about when the
    > compiler ignores asserts and when the compiler is to compile them in and
    > generate code for them. After all, the Standard says nothing debug vs.
    > release builds...[/color]

    assert is defined as ((void)0) if the macro NDEBUG is defined at the point
    where <assert.h> is included. If NDEBUG is not defined, assert is supposed
    to print an error message to stderr and call abort(). The format of the
    error message is implementation-defined, but it must include the source
    file name and line number (and function name in C99).

    Comment

    • Gavin Deane

      #3
      Re: assert()

      "Dave" <better_cs_now@ yahoo.com> wrote in message news:<vrnigbpr5 fb984@news.supe rnews.com>...[color=blue]
      > In a nutshell, what is the behavior of the assert() macro ***as proscribed
      > by the C89 Standard*** (which I don't have)? Of course, it doens't appear
      > in the C++ Standard since it's inherited from C. Hence my inquiry about the
      > C Standard even though I care about this from a C++ perspective...
      >
      > Specifically, I'm wondering what the Standard has to say about when the
      > compiler ignores asserts and when the compiler is to compile them in and
      > generate code for them. After all, the Standard says nothing debug vs.
      > release builds...[/color]

      I don't have the C standard either, but in the C++ standard,
      17.4.2.1/2 mentions the NDEBUG macro. And my understanding is that
      when this macro is not defined, code is generated for an assert, and
      when NDEBUG is defined code is not generated.

      This ties in with the contents of my implementation' s assert.h file.

      GJD

      Comment

      • EventHelix.com

        #4
        Re: assert()

        Checkout the following article for assert handling:



        Sandeep
        --
        Sequence diagram based systems engineering and architecture design tool. Built in support for alternative scenarios and multi-tier architectures.

        EventStudio 2.0 - Generate Sequence Diagrams and Use Case Diagrams in PDF

        Comment

        • NFish

          #5
          Re: assert()

          EventHelix.com wrote:
          [color=blue]
          > Checkout the following article for assert handling:
          >
          > http://www.eventhelix.com/RealtimeMa...y_contract.htm
          >
          > Sandeep[/color]

          Their non-debugging macros do not *not* evaluate their arguments; e.g.

          ASSERT(strlen(f oo) > 10);

          gets expanded to

          strlen(foo) > 10;

          when the _DEBUG flag is not defined. Their code is full of similar
          examples where assert macros generate overhead no matter what. Pretty
          poor example.

          Comment

          Working...