unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: ludo@gnu.org (Ludovic Courtès)
To: guile-user@gnu.org
Subject: Re: gh_new_procedure with c++
Date: Mon, 23 Jun 2008 11:59:17 +0200	[thread overview]
Message-ID: <87lk0w8oay.fsf@gnu.org> (raw)
In-Reply-To: 270252.38285.qm@web26905.mail.ukl.yahoo.com

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.





  reply	other threads:[~2008-06-23  9:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-22 22:13 gh_new_procedure with c++ gianluca giorgolo
2008-06-23  9:59 ` Ludovic Courtès [this message]
2008-06-23 11:47   ` Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87lk0w8oay.fsf@gnu.org \
    --to=ludo@gnu.org \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).