Combining C && C++ Code

This is a discussion on Combining C && C++ Code within the C++ Programming forums, part of the General Programming Boards category; Any Helpful Answer to this Question will be Greatly Appreciated Do you know of a way to conveniently combine C ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    1

    Question Combining C && C++ Code

    Any Helpful Answer to this Question will be Greatly Appreciated

    Do you know of a way to conveniently combine C and C++ source code using Visual C++. extern "C" seems very limited in what can be combined. I have lots of code developed in pure C, and would like to combine it with new C++ code.


    Thank you,

  2. #2
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    Re-declare all the C functions you wish to use as extern "C", from within your C++ code. You should then be able to call all the C functions by linking to your libraries, and use any C++.

    extern "C" is more limiting the other way around, where you are calling C++ functions from within C code, in which case you'd have no choice but cut out much of the the C++ specific code.

  3. #3
    Fingerstyle Guitarist taylorguitarman's Avatar
    Join Date
    Aug 2001
    Posts
    564
    From the example that you gave me it sounds like you're trying to use C++ functions in C code. As Sorenson said that's not always so easy.

    I've only used C code in a C++ project not the other way around.
    You might be looking at changing the code. Good Luck.
    Last edited by taylorguitarman; 02-12-2002 at 01:34 PM.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,848

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Cross (compiler | OS) && reuseable code
    By audinue in forum C Programming
    Replies: 6
    Last Post: 07-22-2008, 01:46 PM
  2. combining c with c++ code
    By verbatimline in forum C++ Programming
    Replies: 3
    Last Post: 07-22-2008, 01:04 PM
  3. Values changing without reason?
    By subtled in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 11:20 AM
  4. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 06:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21