4 ms·
For comparison, here's FreeBSD's abort(): http://svnweb.freebsd.org/base/head/lib/libc/stdlib/abort.c?view=markup http://svnweb.freebsd.org/base/head/lib/libc/
by cpeterso 15y ago
For comparison, here's FreeBSD's abort():
http://svnweb.freebsd.org/base/head/lib/libc/stdlib/abort.c?view=markup http://svnweb.freebsd.org/base/head/lib/libc/stdlib/abort.c?...
And GNU glibc's abort():
http://sourceware.org/git/?p=glibc.git;a=blob_plain;f=stdlib/abort.c http://sourceware.org/git/?p=glibc.git;a=blob_plain;f=stdlib...
- masklinn 15y agoAnd OSX's, which is rather similar to FreeBSD's but adds: * Writing to NULL * Writing to address 1 (unaligned write) * Writing to text space (read-only machine code) * Dividing by 0 * More violence than SIGABRT (SIGILL, SIGBUS) http://www.opensource.apple.com/source/Libc/Libc-262/stdlib/abort.c http://www.opensource.apple.com/source/Libc/Libc-262/stdlib/...
- ajross 15y agoLooks to me like glibc and FreeBSD are the only ones that flush stdout, which I'd view as a bug on the other systems...
- sparky 15y ago(Note: The uclibc implementation in the OP also attempts to flush stdout as part of the _stdio_term() call) It's a bug in the spec, if anything. See the abort() spec http://pubs.opengroup.org/onlinepubs/009695399/functions/abort.html http://pubs.opengroup.org/onlinepubs/009695399/functions/abo... Vs the exit() spec http://pubs.opengroup.org/onlinepubs/000095399/functions/exit.html http://pubs.opengroup.org/onlinepubs/000095399/functions/exi... abort() is intended as a last-ditch effort. exit() is the one that attempts to flush all open buffered file descriptors, and should be used in lieu of abort except in cases where you know you're screwed, or explicitly want to throw a signal so a debugger can take a peek.
- Jabbles 15y agoSince dereferencing a null pointer and dividing by 0 are undefined by C, is the compiler required to emit the code for them? In practice, does it?
- the_mitsuhiko 15y agoIn practice: compilers usually don't touch expressions with volatile vars.
- praptak 15y agoIn practice, <asterisk>(int <asterisk>)0 (how do I escape asterisks on HN?) and similar are popular idioms for "segfault here". Making them break is not an optimization any compiler maintainer would bother to make - it requires a special case and there don't seem to be any benefits to justify the effort.
- deleted 15y ago[deleted]
- jesboat 15y agoSee the series of articles starting with http://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html http://blog.llvm.org/2011/05/what-every-c-programmer-should-...