From b3e9e62599532050fc776c5e8f076915b56c2235 Mon Sep 17 00:00:00 2001 From: David Faulkner Date: Fri, 7 Aug 2026 23:40:47 -0500 Subject: Import official C23 code examples for Modern C (Jens Gustedt, 2024) - Add official C source files, Makefile, c23-fallback.h, and LICENSE - Update README.md with study mirror notice --- crash.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 crash.h (limited to 'crash.h') diff --git a/crash.h b/crash.h new file mode 100644 index 0000000..6f522b8 --- /dev/null +++ b/crash.h @@ -0,0 +1,37 @@ +#ifndef CRASH_H +#define CRASH_H 1 + +/** + ** @brief enable alignment check for i386 processors + ** + ** Intel's i386 processor family is quite tolerant in accepting + ** misalignment of data. This can lead to irritating bugs when ported + ** to other architectures that are not as tolerant. + ** + ** This function enables a check for this problem also for this + ** family or processors, such that you can be sure to detect this + ** problem early. + ** + ** I found that code on Ygdrasil's blog: + ** http://orchistro.tistory.com/206 + **/ + +inline +void enable_alignment_check(void) { +#if defined(__GNUC__) +# if defined(__x86_64__) + __asm__("pushf\n" + "\torl $0x40000, (%%rsp)\n" + "\tpopf" + : : : "cc"); +# elif defined(__i386__) + __asm__("pushf\n" + "\torl $0x40000, (%%esp)\n" + "\tpopf" + : : : "cc"); +# endif +#endif +} + + +#endif -- cgit v1.2.3