Do i need to modify 'c' source to make it compitable with c++ application ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ankit vinayaka
    New Member
    • Apr 2009
    • 5

    Do i need to modify 'c' source to make it compitable with c++ application ?

    hello ,
    I am using ' qt ' for gui frontend for my crypography based program that uses openssl ( 'c' ) library . Do i need to make any kind of major / minor changes to my orignal 'c' program if use qt that is written in c++ ?
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    As long as your original program was written to exposed some sort of interface for its main tasks you should easily be able to write a C++/QT wrapper that makes those same function calls. Continue compiling your old C code as C and compile the new C++ code as C++.

    In you header files declaring the C API you will need to mark the functions in your C code as using the C as opposed to the C++ calling convention. The usual method is to have in the header file
    Code:
    #ifdef __cplusplus
    extern "C" {
    #endif
    
    // Declarations of functions in C source files
    
    #ifdef __cplusplus
    }
    #endif
    This tells the C++ compiler that those functions do not have the mangled (by the compiler) C++ function names but use C function names.

    Comment

    • ankit vinayaka
      New Member
      • Apr 2009
      • 5

      #3
      Thanks for the reaply .

      Comment

      • donbock
        Recognized Expert Top Contributor
        • Mar 2008
        • 2427

        #4
        Certain C99 features are not supported by C++ (long long int, restrict, variadic macros, etc).

        Certain more common C features are not supported by C++ (implicit cast to and from void*, K&R-style function declarations, use of "__" in variable names, etc).

        Certain C features work differently in C++ (library function prototypes differ, C++ keywords can't be used as variable names, etc).

        Take a look at this.

        Comment

        Working...