C++ source code compilation

Discussion in 'C++' started by Sheky, Dec 6, 2011.

  1. Sheky

    Sheky Guest

    Could anyone please answer if every C++ programs get converted to
    equivalent C code during compilation ? Thank you.
     
    Sheky, Dec 6, 2011
    #1
    1. Advertising

  2. Sheky

    red floyd Guest

    red floyd, Dec 6, 2011
    #2
    1. Advertising

  3. Sheky

    Sheky Guest

    On Dec 6, 10:15 pm, red floyd <> wrote:
    > On 12/6/2011 8:49 AM, Sheky wrote:
    >
    > > Could anyone please answer if every C++ programs get converted to
    > > equivalent C code during compilation ? Thank you.

    >
    > Your answer can be found at
    >  http://www.parashift.com/c -faq-lite/how-to-post.html#faq-5.2

    I would like to say it was not a homework problem. I did not know that
    it was possible to convert C++ code to C while compiling except for
    CFront.
    But,Thank you for your answer!! Could you please tell me if g++
    compiler converts c++ source code to C code during compilation? Thank
    you.:)
     
    Sheky, Dec 6, 2011
    #3
  4. On 12/6/2011 1:39 PM, Robert Wessel wrote:
    > On Tue, 6 Dec 2011 10:29:23 -0800 (PST), Sheky
    > <> wrote:
    >
    >> On Dec 6, 10:15 pm, red floyd<> wrote:
    >>> On 12/6/2011 8:49 AM, Sheky wrote:
    >>>
    >>>> Could anyone please answer if every C++ programs get converted to
    >>>> equivalent C code during compilation ? Thank you.
    >>>
    >>> Your answer can be found at
    >>> http://www.parashift.com/c -faq-lite/how-to-post.html#faq-5.2

    >> I would like to say it was not a homework problem. I did not know that
    >> it was possible to convert C++ code to C while compiling except for
    >> CFront.
    >> But,Thank you for your answer!! Could you please tell me if g++
    >> compiler converts c++ source code to C code during compilation?

    >
    >
    > It does not.


    .... and generally speaking, compiler-specific questions should probably
    be posted to the newsgroups dedicated to those compilers (gnu.g++.help
    in this case). See the rest of section 5 of the FAQ.

    V
    --
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Dec 6, 2011
    #4
  5. Sheky

    Paul N Guest

    On Dec 6, 4:49 pm, Sheky <> wrote:
    > Could anyone please answer if every C++ programs get converted to
    > equivalent C code during compilation ? Thank you.


    In addition to what others have said, FAQ 38.13 is probably worth
    reading.
     
    Paul N, Dec 6, 2011
    #5
  6. Leigh Johnston <> wrote:
    > On 06/12/2011 16:49, Sheky wrote:
    >> Could anyone please answer if every C++ programs get converted to
    >> equivalent C code during compilation ? Thank you.

    >
    > Some early C++ compilers worked this way but I suspect very few modern
    > C++ compilers produce C as an intermediate but rather create machine
    > code directly.


    Actually compilers, especially those supporting many languages (such as
    gcc) probably produce a kind of "intermediate" form (which is more or less
    common to all the languages that the compiler supports), which is then
    optimized and compiled into asm. (This intermediate form isn't a programming
    language per se, but usually some tokenized and "half-compiled" tree data in
    binary form, or similar.)

    Anyways, converting a C++ program into C and then compiling that C would
    be inefficient, complicated and produce a less efficient result (because
    the compiler cannot use its knowledge of the C++ syntax in order to better
    optimize the code), so it would make little sense.

    (As an example, I'm guessing that exception handling is impossible to
    convert into C code so that it would be as efficient as when compiling
    C++ directly. C++ exceptions are designed so that if no exception is
    thrown, the code will be as efficient as if no exceptions were in use
    at all. I think this would be impossible to express in C.)
     
    Juha Nieminen, Dec 7, 2011
    #6
  7. Sheky

    ralph Guest

    On Wed, 7 Dec 2011 17:37:14 -0000, "Paul"
    <pchrist<nospam>> wrote:

    >
    >"Juha Nieminen" <> wrote in message
    >news:4edf181e$0$2821$...
    >> Leigh Johnston <> wrote:
    >>> On 06/12/2011 16:49, Sheky wrote:
    >>>> Could anyone please answer if every C++ programs get converted to
    >>>> equivalent C code during compilation ? Thank you.
    >>>
    >>> Some early C++ compilers worked this way but I suspect very few modern
    >>> C++ compilers produce C as an intermediate but rather create machine
    >>> code directly.

    >>
    >> Actually compilers, especially those supporting many languages (such as
    >> gcc) probably produce a kind of "intermediate" form (which is more or less
    >> common to all the languages that the compiler supports), which is then
    >> optimized and compiled into asm. (This intermediate form isn't a
    >> programming
    >> language per se, but usually some tokenized and "half-compiled" tree data
    >> in
    >> binary form, or similar.)

    >
    >Are you suggesting that C++ compilers convert the code to asm, then this asm
    >code is convert to object code?
    >


    Not exactly what he is suggesting, but in process of compiling by
    mainstream compilers (GCC, VC++, Borland, ...) there is a step in
    which preprocessed C++ code is converted to assembly. The assembler
    then converts the 'asm' code into object code.

    >>
    >> Anyways, converting a C++ program into C and then compiling that C would
    >> be inefficient, complicated and produce a less efficient result (because
    >> the compiler cannot use its knowledge of the C++ syntax in order to better
    >> optimize the code), so it would make little sense.
    >>
    >> (As an example, I'm guessing that exception handling is impossible to
    >> convert into C code so that it would be as efficient as when compiling
    >> C++ directly. C++ exceptions are designed so that if no exception is
    >> thrown, the code will be as efficient as if no exceptions were in use
    >> at all. I think this would be impossible to express in C.)

    >
    >Would the same not apply with asm?
    >


    Not really. Or rather there is no asm that couldn't be
    reverse-engineered back into an equivalent expression in another
    higher-level language.

    Thus while performing a C++ to C conversion at the source code level
    would likely lead to a complete mental collapse, a C++ to asm then asm
    to C would be doable - though definitely non-trivial.

    -ralph
     
    ralph, Dec 7, 2011
    #7
  8. On Thursday, December 8, 2011 2:28:29 AM UTC+8, ralph wrote:
    > On Wed, 7 Dec 2011 17:37:14 -0000, "Paul"
    >
    > > wrote:
    >
    > >
    > >"Juha Nieminen" <> wrote in message
    > >news:4edf181e$0$2821$...
    > >> Leigh Johnston <> wrote:
    > >>> On 06/12/2011 16:49, Sheky wrote:
    > >>>> Could anyone please answer if every C++ programs get converted to
    > >>>> equivalent C code during compilation ? Thank you.
    > >>>
    > >>> Some early C++ compilers worked this way but I suspect very few modern
    > >>> C++ compilers produce C as an intermediate but rather create machine
    > >>> code directly.
    > >>
    > >> Actually compilers, especially those supporting many languages (such as
    > >> gcc) probably produce a kind of "intermediate" form (which is more or less
    > >> common to all the languages that the compiler supports), which is then
    > >> optimized and compiled into asm. (This intermediate form isn't a
    > >> programming
    > >> language per se, but usually some tokenized and "half-compiled" tree data
    > >> in
    > >> binary form, or similar.)

    > >
    > >Are you suggesting that C++ compilers convert the code to asm, then this asm
    > >code is convert to object code?
    > >


    What the byte code compiler in C++ and C are different?

    That is funny at all. A tree pass compiler in C++/C with local limited optimization only and can't be inserted with assembly code directly
    is weired.

    Objects are just decorated syntax sugars for structures and function pointers
    as stated clearly in the FAQ in this news group.



    > Not exactly what he is suggesting, but in process of compiling by
    > mainstream compilers (GCC, VC++, Borland, ...) there is a step in
    > which preprocessed C++ code is converted to assembly. The assembler
    > then converts the 'asm' code into object code.
    >
    > >>
    > >> Anyways, converting a C++ program into C and then compiling that C would
    > >> be inefficient, complicated and produce a less efficient result (because
    > >> the compiler cannot use its knowledge of the C++ syntax in order to better
    > >> optimize the code), so it would make little sense.
    > >>
    > >> (As an example, I'm guessing that exception handling is impossible to
    > >> convert into C code so that it would be as efficient as when compiling
    > >> C++ directly. C++ exceptions are designed so that if no exception is
    > >> thrown, the code will be as efficient as if no exceptions were in use
    > >> at all. I think this would be impossible to express in C.)

    > >
    > >Would the same not apply with asm?
    > >

    >
    > Not really. Or rather there is no asm that couldn't be
    > reverse-engineered back into an equivalent expression in another
    > higher-level language.
    >
    > Thus while performing a C++ to C conversion at the source code level
    > would likely lead to a complete mental collapse, a C++ to asm then asm
    > to C would be doable - though definitely non-trivial.
    >
    > -ralph
     
    88888 Dihedral, Dec 7, 2011
    #8
  9. Sheky

    Jorgen Grahn Guest

    On Wed, 2011-12-07, ralph wrote:
    > On Wed, 7 Dec 2011 17:37:14 -0000, "Paul"
    > <pchrist<nospam>> wrote:
    >
    >>
    >>"Juha Nieminen" <> wrote in message
    >>news:4edf181e$0$2821$...
    >>> Leigh Johnston <> wrote:
    >>>> On 06/12/2011 16:49, Sheky wrote:
    >>>>> Could anyone please answer if every C++ programs get converted to
    >>>>> equivalent C code during compilation ? Thank you.
    >>>>
    >>>> Some early C++ compilers worked this way but I suspect very few modern
    >>>> C++ compilers produce C as an intermediate but rather create machine
    >>>> code directly.
    >>>
    >>> Actually compilers, especially those supporting many languages (such as
    >>> gcc) probably produce a kind of "intermediate" form (which is more or less
    >>> common to all the languages that the compiler supports), which is then
    >>> optimized and compiled into asm. (This intermediate form isn't a
    >>> programming
    >>> language per se, but usually some tokenized and "half-compiled" tree data
    >>> in
    >>> binary form, or similar.)

    >>
    >>Are you suggesting that C++ compilers convert the code to asm, then this asm
    >>code is convert to object code?
    >>

    >
    > Not exactly what he is suggesting, but in process of compiling by
    > mainstream compilers (GCC, VC++, Borland, ...) there is a step in
    > which preprocessed C++ code is converted to assembly. The assembler
    > then converts the 'asm' code into object code.


    Are you sure of that? Going to (e.g.) x86 assembly language and then
    invoking the assembler to get x86 object code seems unnecessary
    complication. I don't see it mentioned in the "GCC internals" document.

    /Jorgen

    --
    // Jorgen Grahn <grahn@ Oo o. . .
    \X/ snipabacken.se> O o .
     
    Jorgen Grahn, Dec 7, 2011
    #9
  10. Sheky

    Rui Maciel Guest

    Jorgen Grahn wrote:

    > Are you sure of that? Going to (e.g.) x86 assembly language and then
    > invoking the assembler to get x86 object code seems unnecessary
    > complication. I don't see it mentioned in the "GCC internals" document.


    He is right. GCC is notoriously organized in front-ends, which translate
    any given programming language into an intermediate language which is
    supported by GCC (it appears to support at least 3 intermediate languages),
    and back-ends, which translate code written in those intermediate languages
    into machine code for a specific target platform.

    This approach may appear an "unnecessary complication" at first. Yet, this
    approach means, at least in theory, that you only need to write a new GCC
    front-end in order to get your new programming language to be supported in
    every platform supported by GCC, and it also means that you only need to
    write a new GCC back-end in order to offer support for each and every
    programming language supported by GCC in a brand new target architecture.

    Also, by relying on an intermediate implementation it is also possible to
    perform all sorts of code optimization on a single piece of data and yet
    reap benefits from that optimization when writing code in any programming
    language supported by GCC and when targetting any platform supported by GCC.


    Hope this helps,
    Rui Maciel
     
    Rui Maciel, Dec 7, 2011
    #10
  11. Sheky

    ralph Guest

    On Wed, 07 Dec 2011 14:56:21 -0600, Robert Wessel
    <> wrote:

    >On Wed, 07 Dec 2011 12:28:29 -0600, ralph <>
    >wrote:
    >
    >>On Wed, 7 Dec 2011 17:37:14 -0000, "Paul"
    >><pchrist<nospam>> wrote:
    >>
    >>>
    >>>"Juha Nieminen" <> wrote in message
    >>>news:4edf181e$0$2821$...
    >>>> Leigh Johnston <> wrote:
    >>>>> On 06/12/2011 16:49, Sheky wrote:
    >>>>>> Could anyone please answer if every C++ programs get converted to
    >>>>>> equivalent C code during compilation ? Thank you.
    >>>>>
    >>>>> Some early C++ compilers worked this way but I suspect very few modern
    >>>>> C++ compilers produce C as an intermediate but rather create machine
    >>>>> code directly.
    >>>>
    >>>> Actually compilers, especially those supporting many languages (such as
    >>>> gcc) probably produce a kind of "intermediate" form (which is more or less
    >>>> common to all the languages that the compiler supports), which is then
    >>>> optimized and compiled into asm. (This intermediate form isn't a
    >>>> programming
    >>>> language per se, but usually some tokenized and "half-compiled" tree data
    >>>> in
    >>>> binary form, or similar.)
    >>>
    >>>Are you suggesting that C++ compilers convert the code to asm, then this asm
    >>>code is convert to object code?
    >>>

    >>
    >>Not exactly what he is suggesting, but in process of compiling by
    >>mainstream compilers (GCC, VC++, Borland, ...) there is a step in
    >>which preprocessed C++ code is converted to assembly. The assembler
    >>then converts the 'asm' code into object code.

    >
    >
    >So do, some don't. IIRC, GCC, for example, does, MSVC does not.


    Yeah, I did make is sound like they all output .ASM files. MSVC
    doesn't unless requested.

    But here is where we will likely get into a semantics war over
    "passes", "assembler", and "machine code". <g>

    First off consider what is "asm"? It is merely decorated machine code
    formatted into sections to be human or favorite Assembler readable and
    output to a file. If that is your definition, then MSVC skips that.
    What it produces from preprocessed source code is a formatted, binary
    equivalent - the .obj. That pass is called the "assembler".

    You can get MSVC to output formatted .ASM with a compiler switch. Not
    a very complex process as it just re-formats its internal binary
    representation to text. Furthermore, you can use that .ASM file as a
    full replacement in later operations. Which to me demonstrates the
    only difference is formatting.

    The GCC outputs a documented file, MSVC keeps its cards a little
    closer to the vest, but its there. They all go through an "assembly"
    phase.

    -ralph
     
    ralph, Dec 7, 2011
    #11
  12. Sheky

    John Bokma Guest

    "Paul" <pchrist<nospam>> writes:

    > Object files do not contain machine code.
    > * Shakes head in disbelief*
    >
    > http://en.wikipedia.org/wiki/Machine_code.


    Where we read:

    Almost all executable programs are written in higher-level languages,
    and translated to executable machine code by a /compiler/ and linker.
    (emphasis mine).

    http://en.wikipedia.org/wiki/Object_file
    An object file is a file containing relocatable format /machine code/ that
    is usually not directly executable.
    (emphasis mine)

    --
    John Bokma j3b

    Blog: http://johnbokma.com/ Perl Consultancy: http://castleamber.com/
    Perl for books: http://johnbokma.com/perl/help-in-exchange-for-books.html
     
    John Bokma, Dec 7, 2011
    #12
  13. Sheky

    John Bokma Guest

    John Bokma, Dec 8, 2011
    #13
  14. "Paul" <pchrist <nospam>> wrote:
    > You can't implement C++ exception hadling in asm.


    That's equivalent to saying that you can't implement C++ exception
    handling in machine code. Or, in other words, that C++ cannot be compiled
    (at least not C++ that has exception handling).
     
    Juha Nieminen, Dec 8, 2011
    #14
  15. "Paul" <pchrist <nospam>> wrote:
    > "John Bokma" <> wrote in message
    >> http://en.wikipedia.org/wiki/Object_file
    >> An object file is a file containing relocatable format /machine code/ that
    >> is usually not directly executable.
    >> (emphasis mine)
    >>

    >
    > Don't be an idiot, an object file is not machine code.


    I still find it puzzling why you are deliberately doing this. You *know*
    that you will look like a complete idiot, but you still do it nevertheless.
    Either you find this amusing, or once you have made an error, you simply
    cannot stop, no matter what.

    Is it a mental illness? A birth defect affecting brain processes?
    An extreme personality disorder? Mental retardation?

    It clearly comes and goes in waves. Sometimes you act like a complete
    retard, sometimes there are long relatively calm periods. Is this a bit
    like a manic-depressive disorder?
     
    Juha Nieminen, Dec 8, 2011
    #15
  16. On Thursday, December 8, 2011 9:59:10 AM UTC+8, Paul wrote:
    > "John Bokma" <> wrote in message
    > news:...
    > > "Paul"

    > > writes:
    > >
    > >> Object files do not contain machine code.
    > >> * Shakes head in disbelief*
    > >>
    > >> http://en.wikipedia.org/wiki/Machine_code.

    > >
    > > Where we read:
    > >
    > > Almost all executable programs are written in higher-level languages,
    > > and translated to executable machine code by a /compiler/ and linker.
    > > (emphasis mine).
    > >
    > > http://en.wikipedia.org/wiki/Object_file
    > > An object file is a file containing relocatable format /machine code/ that
    > > is usually not directly executable.
    > > (emphasis mine)
    > >

    >
    > Don't be an idiot, an object file is not machine code.
    > Black is not white, a computer is not a dab radio , is not a telvevison , is
    > not a toaster.Stop being ridiculous please.
    >

    An object file contains machine code.
    Thus, compiler and linker just emit machine code to run on a machine.

    But the 3 layer separation of GCC is good for portabilities of new languages
    to be supported in GCC to emit native machine code if desired.

    The HW separation of GCC is more versatile than MSVC that sticks with X86 only.

    Some compiler authors from cs maybe just don't think in HW very naturally.
     
    88888 Dihedral, Dec 8, 2011
    #16
  17. On Dec 7, 6:28 pm, ralph <> wrote:
    > On Wed, 7 Dec 2011 17:37:14 -0000, "Paul"
    > <pchrist<nospam>> wrote:
    >
    > >"Juha Nieminen" <> wrote in message
    > >news:4edf181e$0$2821$...
    > >> Leigh Johnston <> wrote:
    > >>> On 06/12/2011 16:49, Sheky wrote:



    > >>>> Could anyone please answer if every C++ programs get converted to
    > >>>> equivalent C code during compilation ? Thank you.


    no. Not all C++ compilers use C as an intermediate language. I
    understand very few do. It's slow and (I understand- IANA compiler
    writer) C isn't a particularly good intermediate language.

    > >>> Some early C++ compilers worked this way but I suspect very few modern
    > >>> C++ compilers produce C as an intermediate but rather create machine
    > >>> code directly.

    >
    > >>  Actually compilers, especially those supporting many languages (such as
    > >> gcc) probably produce a kind of "intermediate" form (which is more or less
    > >> common to all the languages that the compiler supports), which is then
    > >> optimized and compiled into asm.


    or directly into machine code.


    > >> (This intermediate form isn't a
    > >> programming
    > >> language per se, but usually some tokenized and "half-compiled" tree data
    > >> in
    > >> binary form, or similar.)

    >
    > >Are you suggesting that C++ compilers convert the code to asm, then thisasm
    > >code is convert to object code?

    >
    > Not exactly what he is suggesting, but in process of compiling by
    > mainstream compilers (GCC, VC++, Borland, ...) there is a step in
    > which preprocessed C++ code is converted to assembly. The assembler
    > then converts the 'asm' code into object code.
    >
    >
    >
    > >>  Anyways, converting a C++ program into C and then compiling that C would
    > >> be inefficient, complicated and produce a less efficient result (because
    > >> the compiler cannot use its knowledge of the C++ syntax in order to better
    > >> optimize the code), so it would make little sense.

    >
    > >>  (As an example, I'm guessing that exception handling is impossible to
    > >> convert into C code so that it would be as efficient as when compiling
    > >> C++ directly. C++ exceptions are designed so that if no exception is
    > >> thrown, the code will be as efficient as if no exceptions were in use
    > >> at all. I think this would be impossible to express in C.)

    >
    > >Would the same not apply with asm?

    >
    > Not really. Or rather there is no asm that couldn't be
    > reverse-engineered back into an equivalent expression in another
    > higher-level language.


    hardly. Compiling is a pretty information lossy process. The chances
    of recovering usable source from machine code is pretty slim.

    > Thus while performing a C++ to C conversion at the source code level
    > would likely lead to a complete mental collapse, a C++ to asm then asm
    > to C would be doable - though definitely non-trivial.


    I'm not convinced disassembly is easier than compiling C++ into C. We
    know people can write C++ compilers there are loads around. C-Front
    specifically compiled into C. Disassembly is a Hard problem.
     
    Nick Keighley, Dec 8, 2011
    #17
  18. On Thursday, December 8, 2011 7:16:03 PM UTC+8, wrote:
    > On Thu, 8 Dec 2011 02:53:40 -0800 (PST), 88888 Dihedral
    > <> wrote:
    >
    > >On Thursday, December 8, 2011 9:59:10 AM UTC+8, Paul wrote:
    > >> "John Bokma" <> wrote in message
    > >> news:...
    > >> > "Paul"
    > >> > writes:
    > >> >
    > >> >> Object files do not contain machine code.
    > >> >> * Shakes head in disbelief*
    > >> >>
    > >> >> http://en.wikipedia.org/wiki/Machine_code.
    > >> >
    > >> > Where we read:
    > >> >
    > >> > Almost all executable programs are written in higher-level languages,
    > >> > and translated to executable machine code by a /compiler/ and linker.
    > >> > (emphasis mine).
    > >> >
    > >> > http://en.wikipedia.org/wiki/Object_file
    > >> > An object file is a file containing relocatable format /machine code/ that
    > >> > is usually not directly executable.
    > >> > (emphasis mine)
    > >> >
    > >>
    > >> Don't be an idiot, an object file is not machine code.
    > >> Black is not white, a computer is not a dab radio , is not a telvevison , is
    > >> not a toaster.Stop being ridiculous please.
    > >>

    > > An object file contains machine code.
    > >Thus, compiler and linker just emit machine code to run on a machine.

    >
    >
    > Except, as pointed out elsethread, when object files contain nothing
    > at all resembling machine code. In byte-code or
    > link-time-code-generation cases, for example.
    >
    >
    > >But the 3 layer separation of GCC is good for portabilities of new languages
    > >to be supported in GCC to emit native machine code if desired.
    > >
    > >The HW separation of GCC is more versatile than MSVC that sticks with X86 only.

    >
    >
    > MSVC currently compiles for x86, x86-64, IPF and ARM. And in the past
    > compiled for Alpha, MIPS and PPC. IPF will be moving to the "past"
    > category in the not too distant future.
    >

    Thanks for your information. I personally use MSVC in Wintel platforms.

    I use GCC in linux/unix/solaris platforms.

    I have co-linux installed under windows with a VNC that can be used to
    test a lot GNU PLOTS, GNU GCC and etc..
     
    88888 Dihedral, Dec 8, 2011
    #18
  19. Sheky

    Rui Maciel Guest

    wrote:

    > Compilers to not output machine code or asm , a compilers output is object
    > code.


    rui@Kubuntu:tmp$ cat main.c
    int main()
    {
    return 0;
    }

    rui@Kubuntu:tmp$ gcc -S main.c -o main.s
    rui@Kubuntu:tmp$ cat main.s
    .file "main.c"
    .text
    .globl main
    .type main, @function
    main:
    ..LFB0:
    .cfi_startproc
    pushq %rbp
    .cfi_def_cfa_offset 16
    .cfi_offset 6, -16
    movq %rsp, %rbp
    .cfi_def_cfa_register 6
    movl $0, %eax
    popq %rbp
    .cfi_def_cfa 7, 8
    ret
    .cfi_endproc
    ..LFE0:
    .size main, .-main
    .ident "GCC: (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1"
    .section .note.GNU-stack,"",@progbits



    > Is this an other idiot thats gonna try and argue that machine code is
    > object code ?


    What's your definition of machine code? And what's your definition of
    object code?


    Rui Maciel
     
    Rui Maciel, Dec 8, 2011
    #19
  20. Sheky

    ralph Guest

    On Thu, 8 Dec 2011 03:41:42 -0800 (PST), Nick Keighley
    <> wrote:


    >>
    >> >>  Anyways, converting a C++ program into C and then compiling that C would
    >> >> be inefficient, complicated and produce a less efficient result (because
    >> >> the compiler cannot use its knowledge of the C++ syntax in order to better
    >> >> optimize the code), so it would make little sense.

    >>
    >> >>  (As an example, I'm guessing that exception handling is impossible to
    >> >> convert into C code so that it would be as efficient as when compiling
    >> >> C++ directly. C++ exceptions are designed so that if no exception is
    >> >> thrown, the code will be as efficient as if no exceptions were in use
    >> >> at all. I think this would be impossible to express in C.)

    >>
    >> >Would the same not apply with asm?

    >>
    >> Not really. Or rather there is no asm that couldn't be
    >> reverse-engineered back into an equivalent expression in another
    >> higher-level language.

    >
    >hardly. Compiling is a pretty information lossy process. The chances
    >of recovering usable source from machine code is pretty slim.
    >


    *Recovering* original source is definitely next to impossible.
    Converting to *equivalent* source code in any language is not.


    >> Thus while performing a C++ to C conversion at the source code level
    >> would likely lead to a complete mental collapse, a C++ to asm then asm
    >> to C would be doable - though definitely non-trivial.

    >
    >I'm not convinced disassembly is easier than compiling C++ into C. We
    >know people can write C++ compilers there are loads around. C-Front
    >specifically compiled into C. Disassembly is a Hard problem.


    It seems most of my associates agree with you. They pointed out that
    once one worked out a framework for fundamental C++ idioms, for
    example a "class", it becomes a matter of updating essentially
    boilerplate code. (Albeit, amazingly ugly code. <g>)

    I find I must agree with them and you. My comment belongs in the realm
    of opinion and not fact, and was based simply on thirty years of
    viewing the asm output of C and translating asm back to C, compared to
    far fewer attempts to convert C++ to C.

    -ralph
     
    ralph, Dec 8, 2011
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Author Tarun Tyagi
    Replies:
    0
    Views:
    749
    Author Tarun Tyagi
    Dec 29, 2004
  2. C__chp
    Replies:
    4
    Views:
    544
    Puppet_Sock
    Feb 15, 2008
  3. Jens-Oliver Murer
    Replies:
    1
    Views:
    487
    Jens-Oliver Murer
    Oct 17, 2008
  4. arunix
    Replies:
    8
    Views:
    475
    Ross A. Finlayson
    Sep 23, 2009
  5. Jenny
    Replies:
    3
    Views:
    299
    Dag Sunde
    Dec 17, 2004
Loading...

Share This Page