fix forced inlining when -O0

threaded
Avril 4 years ago
parent 9ce9cb8c95
commit 9db000e864
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -12,6 +12,12 @@ typedef struct {
void* ptr;
} vec_t;
#ifdef DEBUG
#define _FORCE_INLINE static inline __attribute__((gnu_inline))
#else
#define _FORCE_INLINE extern inline __attribute__((gnu_inline))
#endif
#define VEC_DEFAULT_CAP 16
vec_t vec_new_with_cap(size_t elem, size_t cap);
@ -20,7 +26,7 @@ bool vec_pop(vec_t* restrict self, void* restrict item);
void* vec_index(const vec_t* restrict self, size_t i);
vec_t vec_clone(const vec_t* restrict self);
__attribute__((gnu_inline)) inline extern vec_t vec_new(size_t elem) { return vec_new_with_cap(elem, VEC_DEFAULT_CAP); }
__attribute__((gnu_inline)) inline extern void vec_free(vec_t v) { free(v.ptr); }
_FORCE_INLINE vec_t vec_new(size_t elem) { return vec_new_with_cap(elem, VEC_DEFAULT_CAP); }
_FORCE_INLINE void vec_free(vec_t v) { free(v.ptr); }
#endif /* _VECTOR_H */

@ -3,6 +3,7 @@
#include <string.h>
#include <map.h>
#include <vector.h>
static const char* _prog_name = "fcmp";
@ -13,14 +14,14 @@ static const char* _prog_name = "fcmp";
#define dprintf(fmt, ...)
#endif
__attribute__((noreturn)) static void usage()
__attribute__((noreturn, noinline)) void usage()
{
fprintf(stderr, "fcmp: compare files for identity\n");
fprintf(stderr, "usage: %s <files...>\n", _prog_name);
exit(-1);
}
__attribute__((always_inline)) static inline const void* die_if_null(const void* ptr)
_FORCE_INLINE const void* die_with_usage_if_null(const void* ptr)
{
if (!ptr) usage();
else return ptr;
@ -62,11 +63,11 @@ int main(int argc, char** argv)
const int nrest = argc-2;
if (nrest==0) usage();
dprintf("There are %d extra files to chk", nrest);
const char* f1 = die_if_null(argv[1]);
const char* f1 = die_with_usage_if_null(argv[1]);
const char* frest[nrest];
for (register int i=0;i<nrest;i++) {
frest[i] = die_if_null(argv[2+i]);
frest[i] = die_with_usage_if_null(argv[2+i]);
dprintf("frest[%d] = \"%s\"", i, frest[i]);
}

@ -4,7 +4,7 @@
#include <vector.h>
__attribute__((gnu_inline)) inline static void* die_if_null(void* ptr)
_FORCE_INLINE void* die_if_null(void* ptr)
{
if (!ptr) abort();
return ptr;

Loading…
Cancel
Save