unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* gh_new_procedure with c++
@ 2008-06-22 22:13 gianluca giorgolo
  2008-06-23  9:59 ` Ludovic Courtès
  0 siblings, 1 reply; 3+ messages in thread
From: gianluca giorgolo @ 2008-06-22 22:13 UTC (permalink / raw
  To: guile-user

Hi,

I'm sorry if the question has already been answered on the list but I couldn't find any reference to the topic in the archive (nor in guile user manual).

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'm using guile 1.8.1 and gcc 4.1.3)

Is there any way to avoid the type conversion that apparently g++ doesn't like?

Thanks a lot in advance for any reply!

Gianluca



      ___________________________________ 
Scopri il Blog di Yahoo! Mail: trucchi, novità, consigli... e la tua opinione!
http://www.ymailblogit.com/blog/




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: gh_new_procedure with c++
  2008-06-22 22:13 gh_new_procedure with c++ gianluca giorgolo
@ 2008-06-23  9:59 ` Ludovic Courtès
  2008-06-23 11:47   ` Ludovic Courtès
  0 siblings, 1 reply; 3+ messages in thread
From: Ludovic Courtès @ 2008-06-23  9:59 UTC (permalink / raw
  To: guile-user

Hello,

gianluca giorgolo <giorghy@yahoo.it> 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.





^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: gh_new_procedure with c++
  2008-06-23  9:59 ` Ludovic Courtès
@ 2008-06-23 11:47   ` Ludovic Courtès
  0 siblings, 0 replies; 3+ messages in thread
From: Ludovic Courtès @ 2008-06-23 11:47 UTC (permalink / raw
  To: guile-user

Hi,

ludo@gnu.org (Ludovic Courtès) writes:

> 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.

I just filed a bug:

  https://savannah.gnu.org/bugs/index.php?23681

Thanks,
Ludovic.





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-06-23 11:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-22 22:13 gh_new_procedure with c++ gianluca giorgolo
2008-06-23  9:59 ` Ludovic Courtès
2008-06-23 11:47   ` Ludovic Courtès

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).