Hello, Julian Graham <jool...@gmail.com> skribis:
> Andy and Ludo and I were discussing this on IRC and it was suggested > that we move the question to the mailing list. I'm trying to compile > some code -- using `gcc -pedantic' -- that invokes `scm_c_make_gsubr', > and I'm getting the following warning: > > warning: ISO C forbids passing argument 5 of ‘scm_c_make_gsubr’ > between function pointer and ‘void *’ [-pedantic] > /usr/local/include/guile/2.0/libguile/gsubr.h:63:13: note: expected > ‘scm_t_subr’ but argument is of type ‘struct scm_unused_struct * > (*)(struct scm_unused_struct *, struct scm_unused_struct *)’ > > I was confused, because I was sure that Guile defines scm_t_subr as > `SCM (*) ()', meaning that an `scm_t_subr' is of unspecified arity. > And I was right, but only at libguile compilation time. From __scm.h: > > #ifdef BUILDING_LIBGUILE > typedef SCM (* scm_t_subr) (); > #else > typedef void *scm_t_subr; > #endif The rationale is given above in gsubr.h: /* The type of subrs, i.e., Scheme procedures implemented in C. Empty function declarators are used internally for pointers to functions of any arity. However, these are equivalent to `(void)' in C++, are obsolescent as of C99, and trigger `strict-prototypes' GCC warnings (bug #23681). */ (This refers to <http://savannah.gnu.org/bugs/?23681>.) It is still an obsolescent feature as of C11. Would it work for you to just cast the argument to scm_t_subr? This is what snarf.h (and guile-snarf) does. > Thus the warning: ISO C lets you cast any kind of pointer to `void *' > -- except for a function pointer. [...] > #ifdef __cplusplus > typedef void *scm_t_subr > #else > typedef SCM (* scm_t_subr) (); > #endif > > What do you think? I think it’s not just C++, but also future C standards and current ‘-Wstrict-prototypes’. We can test for C++ or C > 11, but there’s no way do test for -Wstrict-prototypes or -pedantic. There’s #pragma GCC diagnostic, but it cannot be used here. So my current recommendation would be to add an explicit cast to scm_t_subr, unless someone has a better idea. Thanks, Ludo’.