C/C++

Discussion in 'C++' started by Sean M. Tucker, Jul 25, 2004.

  1. Hi,
    I have a project to work on that was done in ANSI C... but I have some code
    done in C++ that I can use. How can I use the C++ code in the C project?

    (I'm using Visual Studio 6, but I wouldn't think it would matter if I was
    using g++ or whatever)

    Thanks.

    -0x53 0x20 0x65 0x20 0x61 0x20 0x6E
    Sean M. Tucker, Jul 25, 2004
    #1
    1. Advertising

  2. Sean M. Tucker

    Phlip Guest

    Sean M. Tucker wrote:

    > I have a project to work on that was done in ANSI C... but I have some

    code
    > done in C++ that I can use. How can I use the C++ code in the C project?
    >
    > (I'm using Visual Studio 6, but I wouldn't think it would matter if I was
    > using g++ or whatever)


    If your C code takes no liberties, compile it as C++. (Any warnings or
    errors you see are your fault. C permits many abuses that are not necessary
    for good code.)

    Under VC++, rename the files to .cpp and add them back to a project.

    --
    Phlip
    http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces
    Phlip, Jul 25, 2004
    #2
    1. Advertising

  3. Sean M. Tucker

    Guest

    A C++ compiler/linker will compile/link both C and C++ code.

    Sean M. Tucker wrote:

    > Hi,
    > I have a project to work on that was done in ANSI C... but I have some
    > code
    > done in C++ that I can use. How can I use the C++ code in the C project?
    >
    > (I'm using Visual Studio 6, but I wouldn't think it would matter if I was
    > using g++ or whatever)
    >
    > Thanks.
    >
    > -0x53 0x20 0x65 0x20 0x61 0x20 0x6E
    , Jul 25, 2004
    #3
  4. Sean M. Tucker

    JKop Guest

    Sean M. Tucker posted:

    > Hi,
    > I have a project to work on that was done in ANSI C...

    but I have some
    > code done in C++ that I can use. How can I use the C++

    code in the C
    > project?
    >
    > (I'm using Visual Studio 6, but I wouldn't think it would

    matter if I
    > was using g++ or whatever)
    >
    > Thanks.
    >
    > -0x53 0x20 0x65 0x20 0x61 0x20 0x6E
    >
    >
    >
    >


    It's just a matter of somehow indicating to the compiler
    that a.cpp is C++ and that b.cpp is C. Then, in your C++
    code, make the function declarations as so:

    extern "C" int Blah(int);


    As for the C code calling C++ functions... no idea.


    -JKop
    JKop, Jul 25, 2004
    #4
    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.

Share This Page