Results 1 to 4 of 4

Thread: Question about differences between c and c++

  1. #1
    Guest

    Smile

    Hey whats up all..

    I have VC++ COMPILER on my puter and i grabbed a bunch of C source codes from a site...so what i am asking is..what huge drastic change of life will i have to go through to use these C codes on my VC++ compiler? ..i have been told there wasnt a huge difference between C and C++ but then again we are dealing with Microsoft Compiler here..so anything is possible.

    Any help will be appreciated.




  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Any C++ compiler will compile C. Just chuck your C source through. Although, if you want to use C functions from C++, you have to use the extern "C" trickery, which is a bit complex and documented on MSDN.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3
    Guest

    Kool thanks but...

    When you say

    "Although, if you want to use C functions from C++, you have to use the extern "C" trickery, which is a bit complex and documented on MSDN."

    You are saying..if i want to use C functions in a C++ program i would have to do that "C" Trick? or if i wanted to use a C++ function in a C program i would have to do the "C" trick?


    Thanks Parksie.














    "I know am an *******..it says so on mah birth certificate!"

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Okay. Here's a scenario:

    You are given a .obj file, compiled on a C compiler by someone. You also have the header file. However, if you just include it, the linker will complain about not finding names. This is because, to support inheritance and overloading, C++ compilers "mangle" function/variable names. Therefore, you would do this:
    Code:
    extern "C" {
    #include "c_include.h"
    }
    which tells the C++ compiler to use the C naming rules when compiling.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width