View Single Post
nicolai's Avatar
Posts: 1,637 | Thanked: 4,424 times | Joined on Apr 2009 @ Germany
#14
Originally Posted by efa View Post
this require me to write my C code inside C++ file, that I do not know, and probably I will damage it.
C++ syntax isn't that different from C.
Originally Posted by efa View Post
Seems more easy to me, keep separate as much as possible the C++ and C, keeping them in different files.
As the C++ part and the C part are for different purpose, separating them is a good idea, like splitting one C program
in different modules.
Originally Posted by efa View Post
For example the C++ code generated by QTCreator remain untouched with them methods, and the C algorithm in my hand written files the same. For sure I will add the C++ method invocation to my C part (like a C function call). It is possible?
...
and then compile both with a C++ compiler.
I wrote the Calendar Home Widget, this is a GTK(hildon) based
widget, just like every other hildon home widget. I use the GTK api,
plain old C datatypes and some C++ objects. But it is actually C++ code and it is compiled with c++.
I had to use this, as the calendar api (calendar-backend) IS a c++ library.
You won't see much difference.
Originally Posted by efa View Post
This let me have more confidence with algorithm file, because I understand error and warning better, as all the file is C syntax but the C++ method invocation only (I do not expect syntax error and problems on QTCreator generated files).
With this solution, the only thing I don't know (apart QT), is how to call a C++ method, the syntax needed (an example of course), taking care that arguments to be passed are variables defined with C syntax, keeping all previous C code intact.
This facilitate the port from a pure CLI C, and also from GTK+ C code.

I suppose will call functions by pointer, and pass variables by pointer (that it is probably what happen to C++ object code when is traslated to C at the start of compilation).
This depends on the type of C++ functions you want to call.

regards
Nicolai