Re: Slightly OT: Compilation question

Discussion in 'C++' started by Tomás Ó hÉilidhe, Jun 14, 2008.

  1. On Jun 13, 12:14 pm, Bit Byte <> wrote:
    > I have some legacy C code that I intend to port over (eventually) to
    > C++.



    What merit is there in porting code from C to C++?

    C is more widely implemented and has more reliable compilers than C++.
    By "porting" the code to C++, you're just making it less portable and
    less reliable.

    If you wanted to take advantage of the extra features in C++, then
    that would involve re-writing the code altogether, which means you
    should just discard the old code (or at the very least just re-write
    the code using the old code as a guide).

    If the C code works perfectly, just leave it be and use a compiler
    which treats .c and .cpp files properly.
    Tomás Ó hÉilidhe, Jun 14, 2008
    #1
    1. Advertising

  2. Tomás Ó hÉilidhe

    Ian Collins Guest

    Tomás Ó hÉilidhe wrote:
    > On Jun 13, 12:14 pm, Bit Byte <> wrote:
    >> I have some legacy C code that I intend to port over (eventually) to
    >> C++.

    >
    >
    > What merit is there in porting code from C to C++?
    >
    > C is more widely implemented and has more reliable compilers than C++.
    > By "porting" the code to C++, you're just making it less portable and
    > less reliable.
    >

    Reliable? There's certainly more platforms with compliant C++ compilers
    than compliant C99 compilers :)

    > If you wanted to take advantage of the extra features in C++, then
    > that would involve re-writing the code altogether, which means you
    > should just discard the old code (or at the very least just re-write
    > the code using the old code as a guide).
    >


    What if you want to expand the code with C++ features? A wholesale
    rewrite is often unnecessary, the port can be gradual. As I said up
    thread (and I've done this a few times): Clean compile as C, add tests,
    compile as C++, pass tests, move on.

    --
    Ian Collins.
    Ian Collins, Jun 14, 2008
    #2
    1. Advertising

  3. On Jun 14, 11:56 pm, Ian Collins <> wrote:

    > What if you want to expand the code with C++ features?



    If you wanted to take an object-orientated approach then that would
    pretty much mean throwing the C code out the window. Use the C code as
    a guide, sure, but that's gone beyond "porting", that's pretty much re-
    writing the code differently.


    > A wholesale
    > rewrite is often unnecessary, the port can be gradual.  As I said up
    > thread (and I've done this a few times):  Clean compile as C, add tests,
    > compile as C++, pass tests, move on.



    But if the code works perfectly already I don't see why they're going
    to the bother of adding C++ features to it? So far I get the feeling
    they're changing printf to cout just for the sake of it.

    Personally, I'd be delighted if I had C code that did a perfect job
    for me, and I'd sooner "port" (or whatever you wanna call it) code
    from C++ to C.
    Tomás Ó hÉilidhe, Jun 15, 2008
    #3
  4. Tomás Ó hÉilidhe

    Ian Collins Guest

    Tomás Ó hÉilidhe wrote:
    > On Jun 14, 11:56 pm, Ian Collins <> wrote:
    >
    >> What if you want to expand the code with C++ features?

    >
    >
    > If you wanted to take an object-orientated approach then that would
    > pretty much mean throwing the C code out the window. Use the C code as
    > a guide, sure, but that's gone beyond "porting", that's pretty much re-
    > writing the code differently.
    >

    What if yo don't? Or if you realises some part would benefit form OO?
    >
    >> A wholesale
    >> rewrite is often unnecessary, the port can be gradual. As I said up
    >> thread (and I've done this a few times): Clean compile as C, add tests,
    >> compile as C++, pass tests, move on.

    >
    > But if the code works perfectly already I don't see why they're going
    > to the bother of adding C++ features to it? So far I get the feeling
    > they're changing printf to cout just for the sake of it.
    >

    Things change. I've been through this porting process a number of
    times, each client had their own valid reasons for doing so. Such a
    port isn't a job I'd take on without making sure the client had
    realistic expectations.

    --
    Ian Collins.
    Ian Collins, Jun 15, 2008
    #4
  5. Tomás Ó hÉilidhe

    Richard Guest

    Tomás Ó hÉilidhe <> writes:

    > On Jun 13, 12:14 pm, Bit Byte <> wrote:
    >> I have some legacy C code that I intend to port over (eventually) to
    >> C++.

    >
    >
    > What merit is there in porting code from C to C++?
    >


    What a ridiculous statement. Are you for real?

    > C is more widely implemented and has more reliable compilers than C++.
    > By "porting" the code to C++, you're just making it less portable and
    > less reliable.


    *cough* Bullshit.

    > If you wanted to take advantage of the extra features in C++, then
    > that would involve re-writing the code altogether, which means you
    > should just discard the old code (or at the very least just re-write
    > the code using the old code as a guide).


    Or just do what he did and ask for experts opinions here ....

    > If the C code works perfectly, just leave it be and use a compiler
    > which treats .c and .cpp files properly.


    Please define properly. Q : are you starting to suck up to the regs
    after they savaged you recently?
    Richard, Jun 15, 2008
    #5
    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. Martin Ambuhl

    Re: Slightly OT: Compilation question

    Martin Ambuhl, Jun 13, 2008, in forum: C++
    Replies:
    7
    Views:
    319
    James Kanze
    Jun 15, 2008
  2. Martin Ambuhl

    Re: Slightly OT: Compilation question

    Martin Ambuhl, Jun 13, 2008, in forum: C Programming
    Replies:
    7
    Views:
    281
    James Kanze
    Jun 15, 2008
  3. Paul Hsieh
    Replies:
    16
    Views:
    510
    James Kanze
    Jun 18, 2008
  4. Paul Hsieh

    Re: Slightly OT: Compilation question

    Paul Hsieh, Jun 14, 2008, in forum: C Programming
    Replies:
    18
    Views:
    447
    James Kanze
    Jun 18, 2008
  5. Tomás Ó hÉilidhe

    Re: Slightly OT: Compilation question

    Tomás Ó hÉilidhe, Jun 14, 2008, in forum: C Programming
    Replies:
    4
    Views:
    251
    Richard
    Jun 15, 2008
Loading...

Share This Page