cog_run and C++ projects

If I attempt to use a project using the C++ compiler, I get errors spit out from any use of cog_run with any variety of function I try. Standard functions, static class functions, extern "C" wrapped functions. All produce the error:
error: invalid conversion from void (*) () to void (*) (void*) [-f permissive]
error: initializing argument 1 of 'int* cog_run(void(*)(void*), int) [-fpermissive]

naturally, putting in -fpermissive in compiler options converts these from errors to warnings but that doesn't mean it's going to work. This error will happen to any C++ project I start even the simple examples from the multicore folder.

Is that part of the library a bust for C++ projects? Do I just have to live with the warnings.

As my ugly workaround to calling a class member function in a C callback I created a global variable that I store the object I want to launch into. In the class header is standard function with no return value or parameters like this
void launchObject();

Calling that function like thus:
g_p_object_to_launch = &myObject; 
cog_run(launchObject, 128);

should callback that function which does:
and the run() method then gets everything setup I/O wise and begins running an endless loop.

Also, if the function that is run by cog_run() terminates under some condition, does the cog get stopped? I would assume so, but the description doesn't specify.


  • I wouldn't recommend cog_run. It is easy because it only has a couple parameters, but it uses malloc to allocate the stack which wastes precious code space. It's also a C-style, whereas your project is in C++.

    Instead, checkout PropWare's Runnable class.

    I'm biased toward using PropWare, so of course I recommend using the whole thing, but if are happy with your current workflow, simply download runnable.h and include it in your project. It does not have any dependencies on other PropWare classes so it's very easy to add to other projects.
  • Awesome. Thanks for that! I'll check it out.
  • I was able to whip up a test of runable.h stripped from the rest of PropWare's classes and it seems to be working well. That's similar to the direction that I was heading with a static member function passed the object to 'run' as a parameter. Just kept getting that error passing the function. The rest of simpletools.h works pretty well for the rest of my needs so I'm not going to jump into the full PropWare library for this job but I'll take a look for the future. I just think in OO anymore, so that's right up my ally.

    Thanks again for sharing!
  • Glad it could be of help. And just so you know, PropWare's build system is compatible with the Simple library - and in fact Simple is even shipped along with PropWare downloads. So if you want to give PropWare (or a full-blown IDE) a try without having to change your source code, you still can.
Sign In or Register to comment.