Re: Compilation issues with a C++ Internet-of-Things Event-Framework

Jiří Baum <[email protected]> Sat, 26 Apr 2014 11:16:03 +1000
Newsgroups gmane.org.user-groups.slug.general
Message-ID <[email protected]>
Hi,

David Lyon:
> When I compile, I get these errors:

> dlyon@dlyon-HP8000SFF:~/IoT/madstuff$ make
>   CC      madstuff.o
> madstuff.cpp: In member function ‘void App::setup()’:
> madstuff.cpp:33:45: warning: converting from ‘void (App::*)()’ to ‘void
> (*)()’ [-Wpmf-conversions]
>          addTimerEvent(2, (void (*)()) &App::timerevent);

A quick Google suggests that converting a pointer to a bound method to a
function pointer is a terrible, non-standard thing to do... They're
about evenly split between suggesting you don't do that, and suggesting
you use -Wno-pmf-conversions to suppress the warning.

The thing is, a pointer to a bound method needs to contain not just the
function pointer but also information about the "this" pointer and about
the virtual table; converting it to a plain pointer throws all that
information away. Only gcc will even let you do that (and still call the
function afterwards).

So, if there's an easy way to avoid it, don't do that. Otherwise, if
you're happy with being gcc-specific, you can suppress the warning.


Cheers

Jiri
-- 
Jiří Baum <[email protected]>
Sabik Software Solutions Pty Ltd
0413 183 117
http://www.baum.com.au/sabik
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html