Porting C++ to C 
Author Message
 Porting C++ to C


Quote:


>: could you tell me of places on the net/sources I can get
>: guidelines on porting C++ code to C. If possible,
>: give me some guidelines yourself.

>It's a near-certainty you won't find a C++ > C converter like a QBASIC > C
>converter.

I didn't feel that he was asking for that, but if he is seeking
that, then he should check out Comeau C++ (it would require a port
from us for him, but otherwise it's quite technically possible,
with complete certainty :)
--
Greg Comeau                   Comeau C/C++ 4.2.45 "so close"
ONLINE COMPILER ==>           http://www.*-*-*.com/
4.2.45.2 during March!        NEW ONLINE: Try out our C99 mode!

--



Wed, 03 Sep 2003 15:09:32 GMT  
 Porting C++ to C

Quote:

> Even if you could, if I may, it may be pointless, but before
> saying that perhaps it's reasonable to provide more
> background on your needs and the purpose of going from C++ to C?
> --

I have the source for a C++ file system driver and would like to convert
this to C because I want to base my file system driver on it (I will use
C because my job will require me to use C for development and I would like
to learn the various issues that apply).

I make sure all my code is as understandable/maintainable/reusable as
possible, that is why I want to follow the best possible porting path.

Robert
--



Wed, 03 Sep 2003 15:10:10 GMT  
 Porting C++ to C
Hello all,

could you tell me of places on the net/sources I can get guidelines on porting
C++ code to C. If possible, give me some guidelines yourself.

The obvious way seems to be to convert CLASSes to STRUCTs, since they are
similar. This will involve declaring function pointers in the STRUCTs where
methods existed in the c++ CLASS declarations. The next step, inheritance
could be tricky. Would it be better to simply create STRUCTs in STRUCTs or
pointers in the STRUCTs to CHILDren and PARENTs?

Thank you.

Robert Williams
--



Mon, 01 Sep 2003 22:55:24 GMT  
 Porting C++ to C


Quote:
>could you tell me of places on the net/sources I can get guidelines on porting
>C++ code to C. If possible, give me some guidelines yourself.

>The obvious way seems to be to convert CLASSes to STRUCTs, since they are
>similar. This will involve declaring function pointers in the STRUCTs where
>methods existed in the c++ CLASS declarations. The next step, inheritance
>could be tricky. Would it be better to simply create STRUCTs in STRUCTs or
>pointers in the STRUCTs to CHILDren and PARENTs?

You will have to end up doing stuff like that.
But I doubt you'll find any sort of guide to doing it.
Even if you could, if I may, it may be pointless, but before
saying that perhaps it's reasonable to provide more
background on your needs and the purpose of going from C++ to C?
--
Greg Comeau                   Comeau C/C++ 4.2.45 "so close"
ONLINE COMPILER ==>           http://www.comeaucomputing.com/tryitout
4.2.45.2 during March!        NEW ONLINE: Try out our C99 mode!

--



Tue, 02 Sep 2003 06:23:56 GMT  
 Porting C++ to C

: could you tell me of places on the net/sources I can get guidelines on porting
: C++ code to C. If possible, give me some guidelines yourself.

It's a near-certainty you won't find a C++ > C converter like a QBASIC > C
converter. As far as porting manually, the two languages are just similar
enough to become confusing. You may well be better off coding from scratch, as
in read the C++ to see what it does then code in C. You will _not_ be able to
"just" swap out C++ functions with C functions and compile on your merry way.

Personally, I find C hard enough, and I stay away from C++ becuse I start
mixing the two. C is Challenging enough the way it is. (:

--
FOOD FOR THOUGHT: 100 calories are used up in the course of a mile run.
The USDA guidelines for dietary fibre is equal to one ounce of sawdust.
The liver makes the vast majority of the cholesterol in your {*filter*}stream.
--



Tue, 02 Sep 2003 12:03:12 GMT  
 Porting C++ to C
[NGs and F'up2 restricted to moderated group]


[...]

Quote:
> The obvious way seems to be to convert CLASSes to STRUCTs, since they are
> similar. This will involve declaring function pointers in the STRUCTs where
> methods existed in the c++ CLASS declarations.

And plan to mimic the 'vtable', i.e. a pointer to a struct containing
function pointers for all the virtual functions in the class.

Quote:
> The next step, inheritance could be tricky. Would it be better to
> simply create STRUCTs in STRUCTs or pointers in the STRUCTs to
> CHILDren and PARENTs?

Pointers in the struct would be ---well--- pointless. A given object is
ever only of one child type, so it doesn't need pointers to its parent
or sister types.

You don't even necessarily need nested structs at all: just copy the
contents of the parent struct, then add fields particular to the child
type at the end.

You may want to look at the gtk libraries, which do all this and more
in order to set up an OO-type GUI toolkit, in C, before you invent it
all yourself, once again.
--

Even if all the snow were burnt, ashes would remain.
--



Tue, 02 Sep 2003 06:24:52 GMT  
 Porting C++ to C


Quote:

>> Even if you could, if I may, it may be pointless, but before
>> saying that perhaps it's reasonable to provide more
>> background on your needs and the purpose of going from C++ to C?
>> --

>I have the source for a C++ file system driver and would like to convert
>this to C because I want to base my file system driver on it (I will use
>C because my job will require me to use C for development and I would like
>to learn the various issues that apply).

>I make sure all my code is as understandable/maintainable/reusable as
>possible, that is why I want to follow the best possible porting path.

Not quite knowing all the issues like project lifecycle, etc,
why does it not make sense to keep the C++ parts in C++ and
the C parts in C?  (I'm not challenging this, just trying to
understand your particular better.)

Also, would something like a port of Comeau C++ to your platform
make sense?  (I ask this sinece Comeau C++ can generate C as
its object code, upon which a custom port for you could work.)

Of course, the amount of C++ in question may be tiny or whatever,
but we're still not familair with all those details.
--
Greg Comeau                 Comeau C/C++ 4.2.45.2 "it's so close"
ONLINE COMPILER ==>         http://www.comeaucomputing.com/tryitout
NEW: Try out libcomo!       NEW: Try out our C99 mode!

--



Thu, 04 Sep 2003 01:56:23 GMT  
 Porting C++ to C

Quote:
> Not quite knowing all the issues like project lifecycle, etc,
> why does it not make sense to keep the C++ parts in C++ and
> the C parts in C?  (I'm not challenging this, just trying to
> understand your particular better.)

My final version will have entirely original code - I would like to make the
driver and future spin-off projects available as shareware and can't use
someone's code. I am converting the example base to C to make it easier to
build on (I will soon be working in a position that requires strictly
C/assembly coding and want to learn C issues in driver development - I am
developing the driver in my spare time).

Anyway, I have already decided that the best way is to convert CLASSes to
STRUCTs (just data members - including function pointers will make things
unnecessarily complicated, and require more functionality to manage them -
if I go to so much trouble to preserve an OO structure why use C at all?.
Best to have floating functions dealing with fixed structs).

Quote:
> Also, would something like a port of Comeau C++ to your platform
> make sense?  (I ask this sinece Comeau C++ can generate C as
> its object code, upon which a custom port for you could work.)
> Of course, the amount of C++ in question may be tiny or whatever,
> but we're still not familair with all those details.

My particular application is too small to require a C++->C translator, and
doing such a thing manually helps me better understand how the code works.
I don't think there'll be very many applications requiring porting C++
device driver code to C (maybe more the other way).

Robert Williams
--



Fri, 05 Sep 2003 12:41:50 GMT  
 Porting C++ to C


Quote:
>> Not quite knowing all the issues like project lifecycle, etc,
>> why does it not make sense to keep the C++ parts in C++ and
>> the C parts in C?  (I'm not challenging this, just trying to
>> understand your particular better.)

>My final version will have entirely original code - I would like to make the
>driver and future spin-off projects available as shareware and can't use
>someone's code. I am converting the example base to C to make it easier to
>build on (I will soon be working in a position that requires strictly
>C/assembly coding and want to learn C issues in driver development - I am
>developing the driver in my spare time).

Ok.  Just realize that that is often not as easy because
different goals complete, but I do note that it is sometimes
necessary despite any possible burdens.

Quote:
>Anyway, I have already decided that the best way is to convert CLASSes to
>STRUCTs (just data members -

Ok.

Quote:
>including function pointers will make things
>unnecessarily complicated, and require more functionality to manage them -
>if I go to so much trouble to preserve an OO structure why use C at all?.
>Best to have floating functions dealing with fixed structs).

If there is some particular behavior which _must_ be needed,
it seems to me that it needs to be complicated, and more or
less equally complicated, whatever alternative route that you take.
If not, it implies the original design many not have been
as correct as possible (or at least was done under some similar
straightjackets).

Quote:
>> Also, would something like a port of Comeau C++ to your platform
>> make sense?  (I ask this sinece Comeau C++ can generate C as
>> its object code, upon which a custom port for you could work.)
>> Of course, the amount of C++ in question may be tiny or whatever,
>> but we're still not familair with all those details.

>My particular application is too small to require a C++->C translator, and
>doing such a thing manually helps me better understand how the code works.
>I don't think there'll be very many applications requiring porting C++
>device driver code to C (maybe more the other way).

We many many customers who do just that.  But of course "many"
in the grand scheme of millions of programmers is statistically
insignificant... hmm, well, so is those doing it in C really.
--
Greg Comeau                 Comeau C/C++ 4.2.45.2 "it's so close"
ONLINE COMPILER ==>         http://www.comeaucomputing.com/tryitout
NEW: Try out libcomo!       NEW: Try out our C99 mode!

--



Sun, 07 Sep 2003 01:13:12 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Newbie porting EventSample.cs to ASP.NET

2. Newbie: separate big .cs file into small .cs files

3. Need C++ text for non cs major course

4. How to show/call Form2.cs from Form1.cs ?

5. Need help of C(/C++) programmer: for porting a tiny Java benchmark test to C(/C++)

6. Porting Borland C++ 5.x (not Builder) to Visual C++

7. Include code in other Cs files

8. Reuse of cs files, namespace, arch advice pls

9. word - automatic numbering/bold/underline/italics

10. How to Generate .cs file at Runtime

11. newbe/cs student, need help w/ code

12. Serial.cs

 

 
Powered by phpBB® Forum Software