From: Bernhard Brodowsky Date: 2012-09-04T20:16:18+09:00 Subject: Re: Common Traps for C extensions Robert Klemme wrote in post #1074390: > On Mon, Sep 3, 2012 at 1:52 AM, Bernhard Brodowsky > wrote: >>> and conversion code with extern "C" with a C++ compiler though. >> >> I defined a function with two VALUE args and a VALUE return type and I >> wanted this to be a method with one argument (plus the self Argument) >> but I always got this error: >> >> error: invalid conversion from 'VALUE (*)(VALUE, VALUE) {aka long >> unsigned int (*)(long unsigned int, long unsigned int)}' to 'VALUE >> (*)(...) {aka long unsigned int (*)(...)}' [-fpermissive] > > As I said, as long as we do not see the code... I suggest you create > a http://sscce.org/ and post it. > > Cheers > > robert Thanks anyway, but I rewrote everything and I am using Rice now, which works much better except that it doesn't automatically handle this problem if the user redefines initialize and it is a little cumbersome to do a workaround since Rice assumes it defines the initialize method itself etc. Maybe I should write this to the Rice developers because I guess nobody wants a Segfault if the user redefines initialize. The smallest code to reproduce my previous looks about like this: extern "C" { VALUE encrypt(VALUE self, VALUE key) { return qNil; } static VALUE Encrypter = qNil; Init_RubyCrypto() { Encrypter = rb_define_class("Encrypter", rb_cObject); rb_define_method(Encrypter, "encrypt", encrypt, 2); } } The problem appears to be that rb_define_method takes a function pointer with a variable number of arguments, but encrypt has 2 arguments and C somehow implicitely casts this while C++ complains. But it doesn't matter anyway now since I use Rice now. Thanks for the help -- Posted via http://www.ruby-forum.com/.