Find the answer to your Linux question:
Results 1 to 5 of 5
Hi , I got a problem about assert() on linux/unix && gcc , I wanna know how does assert() work,I mean that how does the assert() make the programme exit? ...
  1. #1
    Just Joined!
    Join Date
    Oct 2009
    Posts
    6

    How does the assert() work?

    Hi , I got a problem about assert() on linux/unix && gcc , I wanna know how does assert() work,I mean that how does the assert() make the programme exit? Is assert() send SIGSEGV to programme or called function exit() or other ways? Thank you
    Last edited by Cabhan; 05-22-2010 at 04:17 PM. Reason: Reducing font size.

  2. #2
    Linux Engineer GNU-Fan's Avatar
    Join Date
    Mar 2008
    Posts
    935
    Debian GNU/Linux -- You know you want it.

  3. #3
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    The best way to answer this question would be to look at the assert man page. Man pages are a set of documentation built into Linux systems. Run this command from the commandline:
    Code:
    man 3 assert
    It will explain how assert() works. A short summary is that if the expression is false, an error message is printed and abort() is called. To see what abort is, we check its man page:
    Code:
    man 3 abort
    We see here that abort() sends the process a SIGABRT.
    DISTRO=Arch
    Registered Linux User #388732

  4. #4
    Just Joined!
    Join Date
    Oct 2009
    Posts
    6
    Quote Originally Posted by Cabhan View Post
    The best way to answer this question would be to look at the assert man page. Man pages are a set of documentation built into Linux systems. Run this command from the commandline:
    Code:
    man 3 assert
    It will explain how assert() works. A short summary is that if the expression is false, an error message is printed and abort() is called. To see what abort is, we check its man page:
    Code:
    man 3 abort
    We see here that abort() sends the process a SIGABRT.
    Thank you!

  5. #5
    Just Joined! bbchina's Avatar
    Join Date
    May 2010
    Posts
    3
    Quote Originally Posted by lynx1987 View Post
    Hi , I got a problem about assert() on linux/unix && gcc , I wanna know how does assert() work,I mean that how does the assert() make the programme exit? Is assert() send SIGSEGV to programme or called function exit() or other ways? Thank you
    12 assert(!p1);
    (gdb)
    a.out: main.c:12: main: Assertion `!p1' failed.

    Program received signal SIGABRT, Aborted.
    0xb7761424 in __kernel_vsyscall ()

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...