Thread: Little doubt regarding #ifdef __cplusplus

  1. #1
    Registered User
    Join Date
    Dec 2010

    Little doubt regarding #ifdef __cplusplus

    Hi all
    This is my first post in this forum. If there is any mistake please forgive me.
    I have some functions in C code to which variables are passed from C++ files OR some functions in C files are called from C++ file.
    Will it be right if I enclosed definition of those functions in #ifdef __cplusplus ... #endif block in C file? Will those functions be called from C++ file ? OR I have to convert that C file to C++ file... Those functions are defined in so many C files, also there are some variables in C++ files which are used in C files...As the quantity of C files is large,it will be headache to convert those C files to C++ files...
    What is the best way to achieve it?

    Please give me suggestions.... Right now I am following the #ifdef __cplusplus way & it is getting compiled, But I am not sure whether it will run successfully...
    Last edited by rockubaby; 12-07-2010 at 04:14 PM. Reason: Something was missing

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    If you've already got code, then don't touch it. This is why C++ gives you extern C -- surround the function prototype in an extern C block and the linker will know not to mangle the names.

    OR you can just recompile all the code -- don't touch it or edit it in any way (unless you're using reserved words like "class" or something), just add it to your project.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. #ifdef error
    By VirtualAce in forum C++ Programming
    Replies: 2
    Last Post: 01-12-2010, 07:03 PM
  2. Buidl Library with ./configure script
    By Jardon in forum C Programming
    Replies: 6
    Last Post: 07-24-2009, 09:36 AM
  3. ifdef is harmful - but simple workaround is not working
    By amitbern in forum C Programming
    Replies: 15
    Last Post: 12-06-2008, 07:02 AM
  4. Replies: 4
    Last Post: 12-10-2006, 07:08 PM
  5. #ifdef - Can It Be Used With Logic Such as OR / AND?
    By dedham_ma_man in forum C Programming
    Replies: 3
    Last Post: 04-21-2006, 02:57 PM