From 0be620602ad7dd14ddb9f4eb26749759131cb7db Mon Sep 17 00:00:00 2001 From: Alex Helfet Date: Wed, 22 Mar 2017 17:40:05 +0000 Subject: [PATCH] Fix compiler warnings and errors in GCC. --- lib/capn-malloc.c | 4 ++++ lib/capn.c | 2 ++ lib/capnp_c.h | 25 +++++++++++++++++++++---- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/lib/capn-malloc.c b/lib/capn-malloc.c index a3c2de0..708294e 100644 --- a/lib/capn-malloc.c +++ b/lib/capn-malloc.c @@ -25,6 +25,10 @@ struct check_segment_alignment { }; static struct capn_segment *create(void *u, uint32_t id, int sz) { + // Silence warnings about unused parameters. + UNUSED(u); + UNUSED(id); + struct capn_segment *s; sz += sizeof(*s); if (sz < 4096) { diff --git a/lib/capn.c b/lib/capn.c index 60e139c..0677452 100644 --- a/lib/capn.c +++ b/lib/capn.c @@ -7,6 +7,8 @@ * of the MIT license. See the LICENSE file for details. */ +#pragma GCC diagnostic ignored "-Wmissing-field-initializers" + #include "capnp_c.h" #include diff --git a/lib/capnp_c.h b/lib/capnp_c.h index a1133df..86d5608 100644 --- a/lib/capnp_c.h +++ b/lib/capnp_c.h @@ -13,6 +13,12 @@ #include #include + +// ssize_t is defined in unistd.h in GCC. +#ifdef __GNUC__ +#include +#endif + #if defined(unix) && !defined(__APPLE__) #include #endif @@ -22,6 +28,19 @@ typedef intmax_t ssize_t; #endif +// Macro UNUSED silences compiler warnings about unused parameters. +#ifndef UNUSED +#define UNUSED(x) (void)(x) +#endif + +// Cross-platform macro ALIGNED_(x) aligns a struct by x bits. +#ifdef _MSC_VER +#define ALIGNED_(x) __declspec(align(x)) +#endif +#ifdef __GNUC__ +#define ALIGNED_(x) __attribute__ ((aligned(x))) +#endif + #ifdef __cplusplus extern "C" { #endif @@ -103,10 +122,8 @@ struct capn_tree *capn_tree_insert(struct capn_tree *root, struct capn_tree *n); * data, len, cap, and user should all set by the user. Other values * should be zero initialized. */ -#ifdef _MSC_VER -__declspec(align(64)) -#endif -struct capn_segment { + +struct ALIGNED_(64) capn_segment { struct capn_tree hdr; struct capn_segment *next; struct capn *capn;