4 ms·
In your first example you must take care not to run afoul of alignment or aliasing rules. This is not always easy. Using "extern inline" is a bad idea since n
by mansr 15y ago
In your first example you must take care not to run afoul of alignment or aliasing rules. This is not always easy.
Using "extern inline" is a bad idea since no two compilers implement it the same way and none according to spec (that I know of). There is no standard way to force inlining of a function.
- tptacek 15y agoYou're right, if you do the 4-byte lookup trick on a SPARC you'll get a SIGBUS if you do it at arbitrary offsets. It's not always easy to ensure your comparison target is e.g. at the start of your read buffer, or in its own array on the stack, or in the return value from strdup(). It's definitely a "trick", not a proper form. I also wouldn't do "extern inline" on a random C compiler; it works on clang, gcc, and Sun's compiler, though.
- nitrogen 15y agoYou probably know this already, but if you pass -std=c99 to gcc, you have to have a separate definition for your inlined functions. Here's how I do it; I welcome suggestions for improvement: module_a.h: #ifndef INLINE_ # define INLINE_ inline #endif /* INLINE_ */ INLINE_ void function_a() { } inline_defs.c #define INLINE_ #include "module_a.h"