Hi,
I'm running into a compile-time problem passing a C function
pointer to scm_c_define_gsubr, compiling in C++. And yes, I know I'm
using -Werror.
e.g.:
cc1plus: warnings being treated as errors
../../../src/guile/hackt-config.cc: In function 'void
HAC::guile_wrap::wrap_package_string_init()':
../../../src/guile/hackt-config.cc:32: warning: ISO C++ forbids casting
between pointer-to-function and pointer-to-object
This is due to the installed definition of scm_t_subr in libguile/__scm.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). */
#ifdef BUILDING_LIBGUILE
typedef SCM (* scm_t_subr) ();
#else
typedef void *scm_t_subr;
#endif
which is used in the prototype in libguile/gsubr.h:
SCM_API SCM scm_c_define_gsubr (const char *name,
int req, int opt, int rst, scm_t_subr fcn);
and after installation, BUILDING_LIBGUILE is no longer defined. Had the
typedef been kept as SCM (*scm_t_subr)(), then the C++ compiler would have
no reason to complain, as no cast between *function and *object would be
needed.
Can someone explain the rationale for the conditional typedef?
Would it be possible to change it back to a true function pointer?
Even it were conditionally defined to:
typedef void (*scm_t_subr)();
that would be good enough to proceed.
Fang
David Fang
http://www.csl.cornell.edu/~fang/
http://www.achronix.com/