Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #8477
| From | jt@toerring.de (Jens Thoms Toerring) |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: Is there any software porting C++ to C? |
| Date | 2011-08-04 20:38 +0000 |
| Organization | Freie Universitaet Berlin |
| Message-ID | <9a0eavF4qkU2@mid.uni-berlin.de> (permalink) |
| References | <xxsZp.48094$T85.36355@newsfe19.ams2> <49572b2b-49fc-4cd7-9d97-c6891c20d2ef@t38g2000prj.googlegroups.com> <4e3ad745$0$4151$6e1ede2f@read.cnntp.org> <j1ema2$feg$1@dont-email.me> |
Victor Bazarov <v.bazarov@comcast.invalid> wrote:
> On 8/4/2011 1:30 PM, Philipp Klaus Krause wrote:
> > Am 02.08.2011 23:45, schrieb Joshua Maurice:
> >> On Aug 1, 12:25 am, "crea"<n...@invalid.com> wrote:
> >>> I need to port C++ code to C code. It includes templates and classes. Is
> >>> this possible and is there any programs which would do this automatically?
> >>> Or any other help regarding this. Thank you
> >>
> >> You are asking, as explained else-thread, that you are looking for a
> >> way to convert the C++ code to maintainable and readable C code.
> >>
> >> If the C++ code uses exceptions, you're in a world of pain. It's
> >> borderline impossible for this to be automated. C++ exceptions are the
> >> one C++ feature that does not map nicely onto C.
> >
> > Pardon my ignorance (I've never written a C++ compiler), but what's the
> > problem with exceptions? I'd imagine them to be rather straightforward
> > to implement using setjmp()/longjmp().
> I am thinking the complexity is in "stack unwinding", due to the need to
> destruct all local objects still "alive" between the 'try' and 'throw'.
> IOW, it's not as simple as just transferring control from one part of
> the code to the other. C doesn't have the "stack unwinding" need, you see.
Having implemented some kind of analog of exceptions for a
C program of mine this is at least one of the issues (which
requires that you do the "stack unwinding" manually and if
you forget about it you may end up with a lot of trouble,
so it's a lot more "brittle" than what can be done in C++).
Other problems include that setjmp()/longjmp() normally don't
save CPU registers (so you must somehow ensure manually that
no values you may need after a try/catch block can be stored
in registers), you rather can have only a finite stack of re-
cursive try's (or you risk some really hairy problems with what
to do when you run out of memory, which also raises an excep-
tion) etc. And you're always very near at the border to unde-
fined behaviour (I am still not 100% sure that I didn't cross
that line somewhere). In that program it was worth all the
trouble, but having C++ exceptions would have been something
I would have given a lot for;-)
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Is there any software porting C++ to C? "crea" <no@invalid.com> - 2011-08-01 08:25 +0100
Re: Is there any software porting C++ to C? Ian Collins <ian-news@hotmail.com> - 2011-08-01 19:42 +1200
Re: Is there any software porting C++ to C? "crea" <no@invalid.com> - 2011-08-01 08:47 +0100
Re: Is there any software porting C++ to C? "Bo Persson" <bop@gmb.dk> - 2011-08-01 11:21 +0200
Re: Is there any software porting C++ to C? "crea" <no@invalid.com> - 2011-08-01 10:26 +0100
Re: Is there any software porting C++ to C? Ian Collins <ian-news@hotmail.com> - 2011-08-01 21:26 +1200
Re: Is there any software porting C++ to C? "crea" <no@invalid.com> - 2011-08-01 11:16 +0100
Re: Is there any software porting C++ to C? Robert Wessel <robertwessel2@yahoo.com> - 2011-08-01 11:59 -0500
Re: Is there any software porting C++ to C? BGB <cr88192@hotmail.com> - 2011-08-01 14:18 -0700
Re: Is there any software porting C++ to C? James Kanze <james.kanze@gmail.com> - 2011-08-07 11:39 -0700
Re: Is there any software porting C++ to C? Juha Nieminen <nospam@thanks.invalid> - 2011-08-01 08:48 +0000
Re: Is there any software porting C++ to C? "crea" <no@invalid.com> - 2011-08-01 10:29 +0100
Re: Is there any software porting C++ to C? "Waldek M." <wm@localhost.localdomain> - 2011-08-04 21:54 +0200
Re: Is there any software porting C++ to C? Marcel Müller <news.5.maazl@spamgourmet.com> - 2011-08-01 11:29 +0200
Re: Is there any software porting C++ to C? Joshua Maurice <joshuamaurice@gmail.com> - 2011-08-02 14:45 -0700
Re: Is there any software porting C++ to C? Philipp Klaus Krause <pkk@spth.de> - 2011-08-04 19:30 +0200
Re: Is there any software porting C++ to C? Victor Bazarov <v.bazarov@comcast.invalid> - 2011-08-04 13:53 -0400
Re: Is there any software porting C++ to C? jt@toerring.de (Jens Thoms Toerring) - 2011-08-04 20:38 +0000
Re: Is there any software porting C++ to C? Nobody <nobody@nowhere.com> - 2011-08-04 21:54 +0100
Re: Is there any software porting C++ to C? BGB <cr88192@hotmail.com> - 2011-08-04 15:40 -0700
Re: Is there any software porting C++ to C? Uwe Dolinsky <uwe@codeplay.com> - 2011-08-03 07:34 -0700
csiph-web