472,978 Members | 2,109 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Porting library from C to C++ but must maintain backwards compatibility

I need to port a library that is written entirely in C to C++. The
library is supported on quite a few platforms (windows, Solaris,
Linux, AIX, HP-UX, OSX, etc...) and there's quite an existing customer
base that uses it. I need to maintain backwards compatibility such
that existing users won't have to do anything to their existing
applications other than a re-compile when they upgrade to this new
version of the library. I figure that I can rewrite the library in
C++ and provide a C interface for backwards compatiblity. Is my
thinking too simplistic? I'm sure that there are issues that come
into play when doing this, but I can't really think of any. I'm a C
programmer who hasn't done any C++ in quite a few years so if this is
a dumb question, please excuse my ignorance.

Thanks,
Sonny
Jul 22 '05 #1
7 2108
"Sonny" <sl**@pacbell.net> wrote...
I need to port a library that is written entirely in C to C++. The
library is supported on quite a few platforms (windows, Solaris,
Linux, AIX, HP-UX, OSX, etc...) and there's quite an existing customer
base that uses it. I need to maintain backwards compatibility such
that existing users won't have to do anything to their existing
applications other than a re-compile when they upgrade to this new
version of the library. I figure that I can rewrite the library in
C++ and provide a C interface for backwards compatiblity. Is my
thinking too simplistic?
Simplistic would be just recompile your library with a C++ compiler
and be done with it. No need to rewrite.
I'm sure that there are issues that come
into play when doing this, but I can't really think of any. I'm a C
programmer who hasn't done any C++ in quite a few years so if this is
a dumb question, please excuse my ignorance.


The main stumbling point in such situations for me is "why?" What
are you expecting to gain by porting from C to C++?

Victor
Jul 22 '05 #2
Sonny,

Drop me a line if you want an example project for the gcc tool chain
that implements your specs.

Evan Carew

Sonny wrote:
I need to port a library that is written entirely in C to C++. The
library is supported on quite a few platforms (windows, Solaris,
Linux, AIX, HP-UX, OSX, etc...) and there's quite an existing customer
base that uses it. I need to maintain backwards compatibility such
that existing users won't have to do anything to their existing
applications other than a re-compile when they upgrade to this new
version of the library. I figure that I can rewrite the library in
C++ and provide a C interface for backwards compatiblity. Is my
thinking too simplistic? I'm sure that there are issues that come
into play when doing this, but I can't really think of any. I'm a C
programmer who hasn't done any C++ in quite a few years so if this is
a dumb question, please excuse my ignorance.

Thanks,
Sonny


Jul 22 '05 #3
"Victor Bazarov" <v.********@comAcast.net> wrote in message news:<hFXTb.170807$sv6.919779@attbi_s52>...
"Sonny" <sl**@pacbell.net> wrote...
I need to port a library that is written entirely in C to C++. The
library is supported on quite a few platforms (windows, Solaris,
Linux, AIX, HP-UX, OSX, etc...) and there's quite an existing customer
base that uses it. I need to maintain backwards compatibility such
that existing users won't have to do anything to their existing
applications other than a re-compile when they upgrade to this new
version of the library. I figure that I can rewrite the library in
C++ and provide a C interface for backwards compatiblity. Is my
thinking too simplistic?


Simplistic would be just recompile your library with a C++ compiler
and be done with it. No need to rewrite.
I'm sure that there are issues that come
into play when doing this, but I can't really think of any. I'm a C
programmer who hasn't done any C++ in quite a few years so if this is
a dumb question, please excuse my ignorance.


The main stumbling point in such situations for me is "why?" What
are you expecting to gain by porting from C to C++?

Victor


The existing C code base is very old (which isn't necessarily a bad
thing), not well documented (which makes it very difficult to
maintain), and very buggy and difficult to maintain. The idea is to
rewrite everything in C++, expose a C interface and put to rest the
existing C code base out to pastor.

Sonny
Jul 22 '05 #4
"Sonny" <sl**@pacbell.net> wrote...
"Victor Bazarov" <v.********@comAcast.net> wrote in message

news:<hFXTb.170807$sv6.919779@attbi_s52>...
"Sonny" <sl**@pacbell.net> wrote...
I need to port a library that is written entirely in C to C++. The
library is supported on quite a few platforms (windows, Solaris,
Linux, AIX, HP-UX, OSX, etc...) and there's quite an existing customer
base that uses it. I need to maintain backwards compatibility such
that existing users won't have to do anything to their existing
applications other than a re-compile when they upgrade to this new
version of the library. I figure that I can rewrite the library in
C++ and provide a C interface for backwards compatiblity. Is my
thinking too simplistic?


Simplistic would be just recompile your library with a C++ compiler
and be done with it. No need to rewrite.
I'm sure that there are issues that come
into play when doing this, but I can't really think of any. I'm a C
programmer who hasn't done any C++ in quite a few years so if this is
a dumb question, please excuse my ignorance.


The main stumbling point in such situations for me is "why?" What
are you expecting to gain by porting from C to C++?

Victor


The existing C code base is very old (which isn't necessarily a bad
thing), not well documented (which makes it very difficult to
maintain), and very buggy and difficult to maintain. The idea is to
rewrite everything in C++, expose a C interface and put to rest the
existing C code base out to pastor.


Then "porting" is the wrong term for what you're about to undertake. The
proper term would be "rewriting". So, your thinking is not too simplistic
but the word you used in the subject line probably makes you think the task
is easier than it can be. Rewriting is often done because the old code base
has severe limitations and/or not a subject to maintenance. It is usually
not as simple as some might want to think, and using an incorrect name for
the process doesn't help either.

You can take one of two path, IMHO. Perhaps more or, rather, some kind of
combination of the two.

One is to keep the old system as the specification and write the new one
fresh, while making sure it does what the old one was supposed to. This
approach has its disadvantages, of course, and the main one is that there
are going to be _new_ bugs introduced into the new code, and the behaviour
is going to be different because of that. Another disadvantage is that
you will need to design the system (some see it as a good thing, at least
you will know how the system works, but to me there is a time factor). No
doubt, you will have to keep the interface changes at zero. You may only
add to it.

The other is to fix the old system, bring it up to date and up to snuff.
The disadvantage of this approach is that you really need to know what the
old system does and how it does that. So, you will need to figure this out
while fixing it. Besides, you have to work with the older style and
language, which is not necessarily an option (if you aren't so good with C,
for example).

Of course, each of those two ways will keep the code base in some form.
The former will probably keep the C headers and the "shell" of the old
functions, which you will have to populate with new C++ functionality. The
latter will keep most of the functionality intact with patches of new or
fixed code throughout. You could even try to bring some of the functional
code from the old system into the new, if taking the former approach. Is
that a good idea? You will have to decide. But remember that while you
might want to keep working algorithms around, are you sure they are working
and bug-free?

In any case, what you really need is documentation, and nothing is going to
help you create one. You either write it based on what customers tell you
they need, or you write it by looking at what the old system does (or at
least seems to do), that's all for backward compatibility. You cannot
escape the necessity to have such documentation, if only for the sake of
future maintainability of the system.

I've done several such "ports" in my career, and only one thing I can tell
by looking back is that the latter approach, while less attractive, can
actually work better. While seemingly fun ("I get to design the new
system while making it work with real-world existing solutions"), the
former is 99% headache and only 1% excitement.

Good luck!

Victor
Jul 22 '05 #5
"Victor Bazarov" <v.********@comAcast.net> wrote in message news:<utaUb.174776$sv6.929955@attbi_s52>...
"Sonny" <sl**@pacbell.net> wrote...
"Victor Bazarov" <v.********@comAcast.net> wrote in message

news:<hFXTb.170807$sv6.919779@attbi_s52>...
"Sonny" <sl**@pacbell.net> wrote...
> I need to port a library that is written entirely in C to C++. The
> library is supported on quite a few platforms (windows, Solaris,
> Linux, AIX, HP-UX, OSX, etc...) and there's quite an existing customer
> base that uses it. I need to maintain backwards compatibility such
> that existing users won't have to do anything to their existing
> applications other than a re-compile when they upgrade to this new
> version of the library. I figure that I can rewrite the library in
> C++ and provide a C interface for backwards compatiblity. Is my
> thinking too simplistic?

Simplistic would be just recompile your library with a C++ compiler
and be done with it. No need to rewrite.

> I'm sure that there are issues that come
> into play when doing this, but I can't really think of any. I'm a C
> programmer who hasn't done any C++ in quite a few years so if this is
> a dumb question, please excuse my ignorance.

The main stumbling point in such situations for me is "why?" What
are you expecting to gain by porting from C to C++?

Victor


The existing C code base is very old (which isn't necessarily a bad
thing), not well documented (which makes it very difficult to
maintain), and very buggy and difficult to maintain. The idea is to
rewrite everything in C++, expose a C interface and put to rest the
existing C code base out to pastor.


Then "porting" is the wrong term for what you're about to undertake. The
proper term would be "rewriting". So, your thinking is not too simplistic
but the word you used in the subject line probably makes you think the task
is easier than it can be. Rewriting is often done because the old code base
has severe limitations and/or not a subject to maintenance. It is usually
not as simple as some might want to think, and using an incorrect name for
the process doesn't help either.

You can take one of two path, IMHO. Perhaps more or, rather, some kind of
combination of the two.

One is to keep the old system as the specification and write the new one
fresh, while making sure it does what the old one was supposed to. This
approach has its disadvantages, of course, and the main one is that there
are going to be _new_ bugs introduced into the new code, and the behaviour
is going to be different because of that. Another disadvantage is that
you will need to design the system (some see it as a good thing, at least
you will know how the system works, but to me there is a time factor). No
doubt, you will have to keep the interface changes at zero. You may only
add to it.

The other is to fix the old system, bring it up to date and up to snuff.
The disadvantage of this approach is that you really need to know what the
old system does and how it does that. So, you will need to figure this out
while fixing it. Besides, you have to work with the older style and
language, which is not necessarily an option (if you aren't so good with C,
for example).

Of course, each of those two ways will keep the code base in some form.
The former will probably keep the C headers and the "shell" of the old
functions, which you will have to populate with new C++ functionality. The
latter will keep most of the functionality intact with patches of new or
fixed code throughout. You could even try to bring some of the functional
code from the old system into the new, if taking the former approach. Is
that a good idea? You will have to decide. But remember that while you
might want to keep working algorithms around, are you sure they are working
and bug-free?

In any case, what you really need is documentation, and nothing is going to
help you create one. You either write it based on what customers tell you
they need, or you write it by looking at what the old system does (or at
least seems to do), that's all for backward compatibility. You cannot
escape the necessity to have such documentation, if only for the sake of
future maintainability of the system.

I've done several such "ports" in my career, and only one thing I can tell
by looking back is that the latter approach, while less attractive, can
actually work better. While seemingly fun ("I get to design the new
system while making it work with real-world existing solutions"), the
former is 99% headache and only 1% excitement.

Good luck!

Victor


Hey Victor,

Thanks for the reply. I'm leaning towards doing the former as one of
my colleages did a re-write of the library in Java not too long ago.
I figure that I can use that as a starting point. Patching the
current code base isn't really an option anymore because it's so
convoluted that IMO, figuring what it did would take more time that
rewriting it from scratch. My main concern is backwards
compatibility. I've been told that if a customer upgrading to this
new version of the library needs to do anything other than plug it in
and recompile, it's a problem. I hope to avoid issues such as where
the version of the compiler I use to build the library isn't
compatible with the version of the compiler my customers use when
integrating the library into their application.

Sonny
Jul 22 '05 #6
Sonny wrote:

Thanks for the reply. I'm leaning towards doing the former as one of
my colleages did a re-write of the library in Java not too long ago.
I figure that I can use that as a starting point. Patching the
current code base isn't really an option anymore because it's so
convoluted that IMO, figuring what it did would take more time that
rewriting it from scratch. My main concern is backwards
compatibility. I've been told that if a customer upgrading to this
new version of the library needs to do anything other than plug it in
and recompile, it's a problem. I hope to avoid issues such as where
the version of the compiler I use to build the library isn't
compatible with the version of the compiler my customers use when
integrating the library into their application.


In that case what you have isn't a porting issue but a
reimplementation. I'd think of it as an entirely new
product, that just happens to retain the same API as the old
one.

Although it depends on the size of the library, personally
I'd favour the second alternative given by Victor. At least
that way you can tackle the work in stages.

I also think that you'll still need to figure out what the
old code is doing if you hope to replace it. The Java
re-write might not help much if you have to maintain the old
C API.

Anyway a couple of years ago we replaced our geometric
solver library written in fortran with code written in C++.
By retaining the old library we were able to gain confidence
in the replacement by calling the fortran equivalent from
within C++ code, comparing the results, and dumping the
program if a mismatch occurred in debug runs. As an added
precaution we added a facility to enable toggling either the
old or new solver implementation. This was so that if
problems were encountered after release, users could
instruct the application to use the old solvers. After a
release cycle and no bug reports the old library was unhooked.
Jul 22 '05 #7
sl**@pacbell.net (Sonny) writes:
The existing C code base is very old (which isn't necessarily a bad
thing), not well documented (which makes it very difficult to
maintain), and very buggy and difficult to maintain. The idea is to
rewrite everything in C++, expose a C interface and put to rest the
existing C code base out to pastor.


An alternative to this could be to rewrite in OO C, and have a C++
wrapper around that. This isn't as stupid as it seems: if you use
GObject and GLib you can wrap your C objects (GObjects!) using Glibmm
and gmmproc to have a very nice C++ binding.

http://www.gtk.org/
http://gtkmm.sf.net/
--
Roger Leigh

Printing on GNU/Linux? http://gimp-print.sourceforge.net/
GPG Public Key: 0x25BFB848. Please sign and encrypt your mail.
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 22 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jason Mobarak | last post by:
Greetings! Say that it's desirable to provide backwards compatibility for methods of an object, consider the case where... class Foo: def bar (self, a, b): pass ....is a defined class...
25
by: BJörn Lindqvist | last post by:
See: http://www.wxpython.org/quotes.php. especially: "wxPython is the best and most mature cross-platform GUI toolkit, given a number of constraints. The only reason wxPython isn't the standard...
2
by: Anand | last post by:
Hi Are there any tools that would help in porting code from Pyton 2.3 to 2.4 ? I have gone through the whatsnew documents and created a document comparing Python 2.4 to 2.3. But so far has not...
70
by: Michael Hoffman | last post by:
Many of you are familiar with Jason Orendorff's path module <http://www.jorendorff.com/articles/python/path/>, which is frequently recommended here on c.l.p. I submitted an RFE to add it to the...
16
by: Mohanasundaram | last post by:
Hi All, We are working on porting a product written in C and C++ from 32 bit to 64 bit. We need to maintain both 32 bit and 64 bit versions in the future. We took the 32 bit source code and...
0
by: Jonathan Wilson | last post by:
acording to http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&selm=oMoJFXNlDHA.2624%40cpmsftngxa06.phx.gbl one "Ed Dore" said "The VC libraries team is looking at getting more of the sources out...
133
by: Jean-Pierre Mestre | last post by:
Good evening, I have a C software for Windows that I need to port to Redhat Unix. At the moment it works completely fine with the Windows FLOSS compiler lccwin32. I try gcc but now it doesn't...
12
by: pantagruel | last post by:
Hi, I'm thinking of making a WScript based JavaScript library, I can think of some specific non-browser specific scripting examples that should probably make it in, like Crockford's little...
19
by: Dotan Cohen | last post by:
I often see mention of SMBs that either want to upgrade their Windows installations, or move to Linux, but cannot because of inhouse VB apps. Are there any Python experts who I can reference them...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.