473,395 Members | 1,696 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Interface C and C++

3
I need to provide an interface between C and C++ files.
I need to call some C++ methods from .c files.
Can I make a new cpp file with wrapper global functions which can internally call the platform independent cpp functions corresponding to the .c functions?
Do I need to do anything else?
Feb 14 '07 #1
2 1510
svlsr2000
181 Expert 100+
I need to provide an interface between C and C++ files.
I need to call some C++ methods from .c files.
Can I make a new cpp file with wrapper global functions which can internally call the platform independent cpp functions corresponding to the .c functions?
Do I need to do anything else?
All the c functions needs to start with extern c keyword, For further informaiton u can read about name mangling in c and c++, a good online tutorial about c and c++ may contain about it.
Feb 14 '07 #2
AdrianH
1,251 Expert 1GB
All the c functions needs to start with extern c keyword, For further informaiton u can read about name mangling in c and c++, a good online tutorial about c and c++ may contain about it.
Don't try and call a C++ call directly by trying to guess it's name. Mangling is there for a reason, it is so you don't do something that will become incompatible in the future. Using the extern "C" directive will stop mangling from occuring, but can be used for only non-member functions.

This discussion is also on thread http://www.thescripts.com/forum/thread215673.html stating amonst other things that the main() function should be in C++ (unsure if that is true, as the linker should take care of that) and what point would there be, just convert the C files to C++ files, and if using both iostream and stdio, to use sync_with_stdio()

To be quite precise, here is what the illustrious Mr. Stroupstrup says:

"C and C++ I/O can be mixed on a per-character basis. A call of
sync_with_stdio() before the first stream I/O operation in the
execution of a program guarantees that the C-style and C++-style I/O
operations share buffers. A call of sync_with_stdio(false) before the
first stream I/O operatio prevents buffer sharing and can improve I/O
performance on some implementations."

(Stroustrup, B. The C++ Programming Language, Special Edition, p651)
Hope this helps.


Adrian
Feb 14 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Roy Pereira | last post by:
I have an application that is composed of a set of "Content" dlls and a viewer application. The viewer calls a standard set of functions that are present in all the dlls. I maintain this by...
9
by: Anon Email | last post by:
Hi people, I'm learning about header files in C++. The following is code from Bartosz Milewski: // Code const int maxStack = 16; class IStack
4
by: Doug | last post by:
I am working on an existing .NET (C Sharp) component that had a com interface that was used by a VB component. When it was originally written, it had the SSEAssemblyCom class below - minus the two...
3
by: zlst | last post by:
Many technological innovations rely upon User Interface Design to elevate their technical complexity to a usable product. Technology alone may not win user acceptance and subsequent marketability....
6
by: Alex Sedow | last post by:
Example 1 interface I { string ToString(); } public class C : I { public void f() {
20
by: Ole Hanson | last post by:
I am accessing my database through an interface, to allow future substitution of the physical datastore - hence I would like to declare in my Interface that my DAL-objects implementing the...
2
by: Alex Sedow | last post by:
Why interface-event-declaration does not support multiple declarators like event-declaration? Grammar from C# spec: variable-declarators: variable-declarator variable-declarators ","...
0
by: YellowFin Announcements | last post by:
Introduction Usability and relevance have been identified as the major factors preventing mass adoption of Business Intelligence applications. What we have today are traditional BI tools that...
15
by: Xah Lee | last post by:
On Java's Interface Xah Lee, 20050223 In Java the language, there's this a keyword “interface”. In a functional language, a function can be specified by its name and parameter specs....
8
by: rn5a | last post by:
Suppose I have the following class code: Imports System Imports System.Data Imports System.Data.SqlClient Public Class DBSettings Private sqlCmd As SqlCommand Private sqlConn As...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.