guile-user
[Top][All Lists]
Advanced

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

Re: gh_new_procedure with c++


From: Ludovic Courtès
Subject: Re: gh_new_procedure with c++
Date: Mon, 23 Jun 2008 11:59:17 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux)

Hello,

gianluca giorgolo <address@hidden> writes:

> I'm trying to use 'gh_new_procedure' to define a new procedure for Scheme 
> that refers to a c++ function. This function takes more than 0 arguments. But 
> given that the gh_new_procedure is defined as taking a function with no 
> argument, g++ complains about the invalid conversion:
>
> main.cpp:131: error: invalid conversion from ‘scm_unused_struct* 
> (*)(scm_unused_struct*, scm_unused_struct*, scm_unused_struct*, 
> scm_unused_struct*, scm_unused_struct*)’ to ‘scm_unused_struct* (*)()’
> main.cpp:131: error:   initializing argument 2 of ‘scm_unused_struct* 
> gh_new_procedure(const char*, scm_unused_struct* (*)(), int, int, int)’

I think it has to be a C function, not a C++ function, i.e., your
function declaration and definition has to be surrounded by `extern "C"
{ ... }'.

This is because the argument to `gh_new_procedure ()' is *not* a
zero-argument function, but a function with *any* number of arguments.
Until the C99 standard (included), "void (* foo) ()" means "pointer to a
function taking any number of arguments"; in C++, it means "pointer to a
function with no arguments".  Future C standards will probably follow
C++ on that, as noted in the "Future Language Directions" of C99
(Section 6.11.6):

  The use of function declarators with empty parentheses (not
  prototype-format parameter type declarators) is an obsolescent
  feature.

This means Guile will eventually have to find another solution.

Besides, `gh_new_procedure ()' is deprecated in 1.8; you should use
`scm_c_define_gsubr ()' instead.

Thanks,
Ludovic.





reply via email to

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