]> git.draconx.ca Git - cdecl99.git/commitdiff
libcdecl: Prefer __inline in public header with GCC.
authorNick Bowler <nbowler@draconx.ca>
Thu, 21 Dec 2023 16:02:51 +0000 (11:02 -0500)
committerNick Bowler <nbowler@draconx.ca>
Thu, 21 Dec 2023 16:02:51 +0000 (11:02 -0500)
If the library is built using GCC with default options, the configure
tests for inline will determine it is supported, and the installed
headers will use it.

But that doesn't mean the user is running the compiler in the exactly
the same mode when including the headers.  If they then use GCC in
strict C89 mode, "inline" is not recognized as a keyword and compilation
will fail.  We can avoid this problem by just always using __inline on
GCC, with a fallback to the configure-detected result.

src/cdecl.h

index 97f39bca800d8b49fb9be56daeccc5a806798fff..63034f4bf11d946bbb9fb98bb66ffc7f92a66343 100644 (file)
 #include <stddef.h>
 #include <stdint.h>
 
+#if __GNUC__
+#  define CDECL__INLINE __inline
+#else
+#  define CDECL__INLINE inline
+#endif
+
 /* Compatibility typedefs */
 #if HAVE__BOOL
 typedef _Bool cdecl_bool;
@@ -109,12 +115,12 @@ void cdecl_free(struct cdecl *decl);
 size_t cdecl_explain(char *buf, size_t n, struct cdecl *decl);
 size_t cdecl_declare(char *buf, size_t n, struct cdecl *decl);
 
-static inline int cdecl_spec_kind(const struct cdecl_declspec *spec)
+static CDECL__INLINE int cdecl_spec_kind(const struct cdecl_declspec *spec)
 {
        return spec->type & ~(CDECL_SPEC_TYPE-1u);
 }
 
-static inline int cdecl_is_abstract(const struct cdecl_declarator *d)
+static CDECL__INLINE int cdecl_is_abstract(const struct cdecl_declarator *d)
 {
        while (d->child)
                d = d->child;