Hi,
I'd appreciate any thoughts on mixing C++ and C code. I have a project that
uses a given C interface, the rest of the project can be either in C or C++.
What would be the recomended design pattern in this case? C++ allows for a
better design, but integrating the code with the C code isn't straight
forward, it becomes rather messy. Code readability and maintenance are
important, since the project will grow in the future. Maybe someone could
speak from personal experience about this.
Thanks,
Cristian 4 1928
Cristian Tota wrote: Hi,
I'd appreciate any thoughts on mixing C++ and C code. I have a project that uses a given C interface, the rest of the project can be either in C or C++. What would be the recomended design pattern in this case? C++ allows for a better design, but integrating the code with the C code isn't straight forward, it becomes rather messy. Code readability and maintenance are important, since the project will grow in the future. Maybe someone could speak from personal experience about this.
It might be a good idea to wrap a C++ class interface around the C API,
so that this API is used directly only in small parts of your program.
"Cristian Tota" <cr***********@ vion-software.ro> wrote in message
news:bq******** **@ally.taide.n et... Hi,
I'd appreciate any thoughts on mixing C++ and C code. I have a project
that uses a given C interface, the rest of the project can be either in C or
C++. What would be the recomended design pattern in this case? C++ allows for a better design, but integrating the code with the C code isn't straight forward, it becomes rather messy. Code readability and maintenance are important, since the project will grow in the future. Maybe someone could speak from personal experience about this. http://www.parashift.com/c++-faq-lit...c-and-cpp.html http://www.comeaucomputing.com/techtalk/#externc
HTH,
-Mike
On Thu, 4 Dec 2003 01:17:05 +0200, "Cristian Tota"
<cr***********@ vion-software.ro> wrote: Hi,
I'd appreciate any thoughts on mixing C++ and C code. I have a project that uses a given C interface, the rest of the project can be either in C or C++. What would be the recomended design pattern in this case? C++ allows for a better design, but integrating the code with the C code isn't straight forward, it becomes rather messy. Code readability and maintenance are important, since the project will grow in the future. Maybe someone could speak from personal experience about this.
Thanks, Cristian
stand-alone functions, you can wrap in
extern "C"
{
int foo(){}
}
If you need to expose classes to C, you can concatenate the class name
to the function names, make them extern "C" and pass to them an extra
static pointer to substitute the this pointer. Member variables become
file-scope static variables.
A few issues back of CUJ there was an article on state machines which
presented object oriented code techniques in C to go with it.
But, usually, for interfacing you'll probably just need interface
classes --i.e. just functions, probably static, which you can collect
into ,C files, which in turn call the C++ code.
Hope it helps.
Cheers!
Cristian Tota wrote: I'd appreciate any thoughts on mixing C++ and C code. I have a project that uses a given C interface.
What does that mean?
Do you mean that you have libraries implemented in C?
The rest of the project can be either in C or C++. What would be the recommended design pattern in this case? C++ allows for a better design but integrating the code with the C code isn't straight forward.
If you say so.
It becomes rather messy.
It shouldn't.
Code readability and maintenance are important since the project will grow in the future.
Try to use C++ for the "rest of the project".
Maybe someone could speak from personal experience about this.
If you have source code for your C code,
try to compile it with your C++ compiler.
It is *much* easier to link object code together
if they are all compiled with the same compiler.
If you don't have all of the C source code (just the library archives),
extern "C" can be used to *help* with linkage. Try using
extern "C" {
#include <file.h>
}
to include your C header files.
Use inline functions to define C++ [member] functions, operators
and constructors which call the "C interface" so that
no *direct* references to the C interface
appear in your application source code. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: bergel |
last post by:
Hello,
Does anyone already have some experience in mixing AWT and Swing? Is it
conceptually doable?
Does the design of Swing prevent interaction between an AWT and a Swing
widget?
Regards,
Alexandre
|
by: Russell E. Owen |
last post by:
At one time, mixing for x in file and readline was dangerous. For
example:
for line in file:
# read some lines from a file, then break
nextline = readline() # bad
would not do what a naive user might expect because the file iterator
buffered data and readline did not read from that buffer. Hence the call
to readline might unexpectedly skip some lines.
|
by: Erik Max Francis |
last post by:
Is there any prohibition against mixing different protocols within the
same pickle? I don't see anything about this in the Python Library
Reference and, after all, the pickle.dump function takes a protocol
argument for each time it's called. (This is in Python 2.3.3.)
I have a pickle containing two objects: a tag string and a (large)
object containing many children. The identifying string is there so
that you can unpickle it and...
|
by: Rudolf |
last post by:
Is it possible to add a vb.net source code module to a c#
project and if so how?
Thanks
Rudolf
|
by: Marc Cromme |
last post by:
I would like to ask a question about (good ?) style and possibilities in
mixing C FILE* and C++ file streams.
The background is that I want to use the C libpng library from within C++,
but I would like to open C++ file streams due to easier exception
handeling and safe closure of file ressources.
Question 1:
I open a standard file stream and want to transfer some binary read bits
| |
by: Dan |
last post by:
Hi
What are the dangers of mixing asp and asp.net? For the .net part of the
site i will need to use the global.asax file but for the asp parts it will
be using the other global. file, is there anyway to get to both use the same
one?
For example i want to convert my homepage to aspx first, but in doing so my
session var that needs to be initialised wont be as it will use the
global.asax and not the global.asa.
|
by: dhruba.bandopadhyay |
last post by:
I know that it's possible to mix ASP & ASP.NET 1.1 in the same
website/application so long as they are in separate frames (iframes).
This
also holds for mixing ASP & ASP.NET 2.0 pages. But what I haven't
tried
is mixing ASP.NET 1.1 & ASP.NET 2.0 pages in the same
website/application
but each page in different iframes.
I don't think it's possible to to have both ASP.NET 1.1 & 2.0 pages in
|
by: ziman137 |
last post by:
Hello all,
I have a question and am seeking for some advice.
I am currently working to implement an algorithmic library. Because
the performance is the most important factor in later applications, I
decide to write it in C instead of C++. However, I thought it might be
convenient to use some C++ code at some misc places. I'm aware that, I
could always use the C++ compiler to get it work.
|
by: jason |
last post by:
I've been working with C# for over a year now without touching vb.net
code. I had a few light years of vb.net before that. No real vb6 or
windows form experience.
Suddenly, I have an assignment where I've been asked to create a few
new pages on an exsisting website. The website is written in vb.net
with vb.net codebehind and classes.
My employer says I can use C# for new stuff If I want.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |