Subject: | "static inline" is invalid for gcc in strict ANSI C mode |
Hello,
Compiling some code that includes "xshelper.h" with perl 5.14 and gcc in strict ANSI C mode (enabled with -std=c89) results in compilation errors when STATIC_INLINE is used. This can be reproduced for e.g. Mouse :
$ perl5.14.4 Makefile.PL OPTIMIZE="-std=c89"
$ make
...
xs-src/Mouse.xs:196:1: erreur: unknown type name ‘inline’
xs-src/Mouse.xs:196:17: erreur: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
For this version of perl, STATIC_INLINE is not defined by perl but __GNUC__ is true, so STATIC_INLINE gets defined to "static inline". But this is invalid for strict C89 compliants C compilers, hence the compilation error :
$ cat hello.c
#include <stdio.h>
static inline const char *hello_world(void) {
return "hello world";
}
int main(void) {
printf("%s\n", hello_world());
return 0;
}
$ gcc -std=c89 -o hello hello.c
hello.c:2:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘const’
I suggest fixing this issue just by removing the __GNUC__ part of the define, as in the attached patch.
Vincent
Subject: | module-install-xsutil-perl514-static-inline.patch |
--- lib/Module/Install/XSUtil.pm 2013-09-05 21:51:56.000000000 +0200
+++ lib/Module/Install/XSUtil.pm 2013-09-05 21:52:24.000000000 +0200
@@ -707,7 +707,7 @@
:/* portability stuff not supported by ppport.h yet */
:
:#ifndef STATIC_INLINE /* from 5.13.4 */
-:# if defined(__GNUC__) || defined(__cplusplus) || (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L))
+:# if defined(__cplusplus) || (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L))
:# define STATIC_INLINE static inline
:# else
:# define STATIC_INLINE static