Date: Fri, 24 Feb 2012 13:13:32 -0600 (CST) From: Robert Bonomi <bonomi@mail.r-bonomi.com> To: freebsd-questions@freebsd.org Subject: Re: Converting C++ to C Message-ID: <201202241913.q1OJDWLp052080@mail.r-bonomi.com> In-Reply-To: <201202241207.q1OC75HG062038@fire.js.berklix.net>
index | next in thread | previous in thread | raw e-mail
"Julian H. Stacey" <jhs@berklix.com> wrote;
> perryh@pluto.rain.com wrote:
> > Reason: I want to make what I think would be a fairly minor
> > change to a small (1100-line) C++ program, but I don't know C++
> > -- only C -- and I don't understand the program well enough
> > to mess with it. I suspect I would be able to figure out an
> > equivalent C program.
> >
> > In case it matters, I'm using FreeBSD 8.1.
>
> One of the lists recently (maybe 2/3 weeks ago) carried a thread
> listing many C compilers past & present. It started by discussing
> Clang V. GCC I can't remember which list, I don't think it was
> questions@ maybe hackers@ or current@.
There _was_ a recent discussion on 'questions' -- I'm the 'guilty party'
responsible for naming a lot of the 'historical' ones.
That aside, for the OP:
C code generated from C++ will _not_ be very readable.
Basically, -everything- in C++ would get turned into a function invocation
in the generated C. With the _name_ of each such function having an encoded
representation of the type of each argument to that function (see 'function
name mangling). And the "simple" elementary data types tend to end up as
something like: "**struct foo {bar value; (*(**struct foo)baz())[];}".
Some of the mayhem: _everything_ is 'double indirect' pointers, to support
run-time automatic garbage collection; 'methods' of acting on data elements
are pointers to functions, embedded in the data-element structure, even
basic 'four function calculator' arithmetic ops (they can be 'overlaid'
to do differnt things on different data types -- the '+' operator may
mean 'concatenation' when applied to two strings, or '+=' maay mean
'append item to list, in the contest of 'list += item', even though both
would *still* mean 'addition' when used with numeric items.)
One would be far better off spending some time to learn the basics of C++
syntax -- to be able to 'read' the existing code and understand what it's
doing. After that, if what you want to modiy -is- truely a 'minor' change,
adding some 'C-tyee' code to implement it is probably not that bad.
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201202241913.q1OJDWLp052080>
