If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Re: calling c++ function from c

Note First Thing you Should Know the difference Between c and C++

in C there is no class.so you can't call a c++ code to c but yes you can call you C code to C++.but as according to your code you are not doing anything which is related with C++.
So make a simple structure and use it in your c code.and you can make a call to your .h file header file .will suggest you to go for preprocessor put your function in the your newly created h file and then call this to you in your code.

Re: calling c++ function from c

Read up on extern "C" - Using extern to Specify Linkage. Apart from the fact that Humpty told (no class constructs in C...), there is one more major difference. The name mangling/decoration in C++ makes it difficult to make calls to C++ routines from C. Note - you can ony use POD types to operate between C and C++ code. You can get to know what POD types are in this thread - Destruction??? Hope this helps. Regards.

The fact that a function is declared extern "C" doesn't mean it can be called from C. It must also only types that are valid in C. However contrary to belief, you may includes pointers to classes if they are only forwardly declared as structs, although you should also include the word "struct" in the function prototype. Thus:

Re: calling c++ function from c

....is a valid C prototype and someType in reality could be a C++ class.

with certain limitations as quoted below from C++ FAQ Lite:

A POD type is a C++ type that has an equivalent in C, and that uses the same rules as C uses for initialization, copying, layout, and addressing.

As an example, the C declaration struct Fred x; does not initialize the members of the Fred variable x. To make this same behavior happen in C++, Fred would need to not have any constructors. Similarly to make the C++ version of copying the same as the C version, the C++ Fred must not have overloaded the assignment operator. To make sure the other rules match, the C++ version must not have virtual functions, base classes, non-static members that are private or protected, or a destructor. It can, however, have static data members, static member functions, and non-static non-virtual member functions.

The actual definition of a POD type is recursive and gets a little gnarly. Here's a slightly simplified definition of POD: a POD type's non-static data members must be public and can be of any of these types: bool, any numeric type including the various char variants, any enumeration type, any data-pointer type (that is, any type convertible to void*), any pointer-to-function type, or any POD type, including arrays of any of these. Note: data-pointers and pointers-to-function are okay, but pointers-to-member are not. Also note that references are not allowed. In addition, a POD type can't have constructors, virtual functions, base classes, or an overloaded assignment operator.

* The Perfect Platform for Game Developers: Android
Developing rich, high performance Android games from the ground up is a daunting task. Intel has provided Android developers with a number of tools that can be leveraged by Android game developers.

* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.