guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: guile-2.0 scm_t_subr typedef


From: Ludovic Courtès
Subject: Re: guile-2.0 scm_t_subr typedef
Date: Tue, 01 Mar 2011 21:33:44 +0100
User-agent: Gnus/5.110013 (No Gnus v0.13) Emacs/23.2 (gnu/linux)

Hi David,

David Fang <address@hidden> writes:

> /* 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).  */

(See <http://savannah.gnu.org/bugs/?23681>.)

> #ifdef BUILDING_LIBGUILE
> typedef SCM (* scm_t_subr) ();
> #else
> typedef void *scm_t_subr;
> #endif

[...]

> 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 explained above, it would complain because in C++ an empty declarator
means that the function takes zero arguments, whereas in C it means that
the function prototype is undefined—i.e., the function can take any
number of arguments of any type.

If you think the comment can be improved, please let me know.

> 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

In C++, instead of writing, say:

--8<---------------cut here---------------start------------->8---
  extern SCM bar (SCM x, SCM y);

    ...
    scm_c_define_gsubr ("foo", 1, 2, 3, &bar);
--8<---------------cut here---------------end--------------->8---

you must write:

--8<---------------cut here---------------start------------->8---
  extern SCM bar (SCM x, SCM y);

    ...
    scm_c_define_gsubr ("foo", 1, 2, 3, (scm_t_subr) &bar);
--8<---------------cut here---------------end--------------->8---

(Tested with G++ 4.5.1 -Wall.)

If you use ‘guile-snarf’, it should do the right thing.

Hope this helps,
Ludo’.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]