From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: ludo@gnu.org (Ludovic =?iso-8859-1?Q?Court=E8s?=) Newsgroups: gmane.lisp.guile.user Subject: Re: gh_new_procedure with c++ Date: Mon, 23 Jun 2008 11:59:17 +0200 Message-ID: <87lk0w8oay.fsf@gnu.org> References: <270252.38285.qm@web26905.mail.ukl.yahoo.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1214215262 27683 80.91.229.12 (23 Jun 2008 10:01:02 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 23 Jun 2008 10:01:02 +0000 (UTC) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Mon Jun 23 12:01:46 2008 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KAirl-0001cM-HE for guile-user@m.gmane.org; Mon, 23 Jun 2008 12:01:41 +0200 Original-Received: from localhost ([127.0.0.1]:43821 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KAiqw-0000J2-CB for guile-user@m.gmane.org; Mon, 23 Jun 2008 06:00:50 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KAiph-0008KU-By for guile-user@gnu.org; Mon, 23 Jun 2008 05:59:33 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KAipf-0008Ir-0q for guile-user@gnu.org; Mon, 23 Jun 2008 05:59:32 -0400 Original-Received: from [199.232.76.173] (port=47686 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KAipe-0008Il-JF for guile-user@gnu.org; Mon, 23 Jun 2008 05:59:30 -0400 Original-Received: from main.gmane.org ([80.91.229.2]:49672 helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KAipd-0001jI-Kq for guile-user@gnu.org; Mon, 23 Jun 2008 05:59:29 -0400 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1KAipZ-0004HX-KF for guile-user@gnu.org; Mon, 23 Jun 2008 09:59:25 +0000 Original-Received: from 193.50.110.161 ([193.50.110.161]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 23 Jun 2008 09:59:25 +0000 Original-Received: from ludo by 193.50.110.161 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 23 Jun 2008 09:59:25 +0000 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 32 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 193.50.110.161 X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 6 Messidor an 216 de la =?iso-8859-1?Q?R=E9volution?= X-PGP-Key-ID: 0xEA52ECF4 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 821D 815D 902A 7EAB 5CEE D120 7FBA 3D4F EB1F 5364 X-OS: i686-pc-linux-gnu User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux) Cancel-Lock: sha1:n1Gc0dMAlcW8GCk5GZy9oSdJR3w= X-detected-kernel: by monty-python.gnu.org: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:6614 Archived-At: Hello, gianluca giorgolo 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.