Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

invalid conversion from ‘void (*)()’ to ‘void (*) .... 1

Status
Not open for further replies.

Hemo

Programmer
Apr 9, 2003
190
0
0
US
gcc 4.1.2 on OpenSuSE 10.2

Error during make:
[tt]
gcc -DHAVE_CONFIG_H -I. -I. -I.. -I/opt/kde3/include -I/usr/lib/qt3/include -I. -DQT_THREAD_SUPPORT -D_REENTRANT -D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING -fno-strict-aliasing -pipe -Wdeclaration-after-statement -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/lib/perl5/5.8.8/i586-linux-thread-multi/CORE -Wnon-virtual-dtor -Wno-long-long -Wbad-function-cast -Wundef -Wall -W -Wpointer-arith -D_XOPEN_SOURCE=500 -D_BSD_SOURCE -Wcast-align -Wconversion -O2 -fno-exceptions -fno-check-new -Wno-write-strings -Wno-unused -c -o kperl.o `test -f 'kperl.cpp' || echo './'`kperl.cpp
cc1plus: warning: command line option "-Wdeclaration-after-statement" is valid for C/ObjC but not for C++
cc1plus: warning: command line option "-Wbad-function-cast" is valid for C/ObjC but not for C++
kperl.cpp: In function ‘void perl_init(KConfig*)’:
kperl.cpp:261: error: invalid conversion from ‘void (*)()’ to ‘void (*)(PerlInterpreter*)’
kperl.cpp:261: error: initializing argument 2 of ‘int perl_parse(PerlInterpreter*, void (*)(PerlInterpreter*), int, char**, char**)’
[/tt]

Line 261 of kperl.cpp:
Code:
        perl_parse(my_perl, xs_init, 3, (char**)perl_args, (char **)NULL);

I'd appreciate any help anyone could offer. I'm not a c++ programmer and some of this goes beyond me. This is from code from an author that has passed away and it _used_ to compile fine on earlier versions of gcc, though it complains more now and errors on the above.
 
You have to prototype the function.
 
Umm.. ok.

As I stated, I'm not C++ programmer, but have doen some research and think I did this right, it compiles without any errors at least.

I found references to:
static void xs_init();

and changed these to :
static void xs_init(PerlInterpreter*);


could it really be that simple? Now I'm off to correct some invalid lvalues in another module...


 
blast, can't edit my previous post. I forgot to thank xwb for the reply. Thanks!
 
I was frustrated at the short reply at first, but I appreciate being taught to feed myself, too. I later found a different way to prototype the function. I reversed the changes I did in my first reply related to xs_init and did the following instead.

From this:
Code:
perl_parse(my_perl, xs_init, 3, (char**)perl_args, (char **)NULL);

to this:
Code:
perl_parse(my_perl, (void (*)(PerlInterpreter *))xs_init, 3, (char**)perl_args, (char **)NULL);
 
That is not such a good idea. Where possible, try to avoid casting as much as possible.

1) Is xs_init declared before the routine is used as. If it isn't, it ought to be: that is what prototyping is all about. It should be something like

void xs_init (PerlInterpreter*);

2) What are perl_args defined as? It should be something like

char** perl_args;

or

char* perl_args[];

What you should feed in is

perl_parse(my_perl, xs_init, 3, &perl_args, (char***) NULL);

You've probably heard the term MIRANDA as used in US cop movies. Well, prototypes are the same (hence Miranda prototypes). If you do not provide one, one will be provided for you. The default is that it returns int.
 
thanks for the extra info. Based on your reply it looks like I was correct with my first changes to xs_init.

Yes, xs_init was declared before the routine gets used, but it was declared thus:
void xs_init ();

so I changed that back to
void xs_init(PerlInterpreter*);

I have some lvalue errors in a different module that I need to figure out before I can link and see if things work.

Thanks for the info.
 
In C,

void xs_init();

means I don't know what the parameters are. It may or may not have parameters. In C++, it means there are no parameters. If you'd compiled it as a C program, it probably would have worked.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top