extern "c" usage?!!

Discussion in 'C++' started by Medvedev, Jul 6, 2008.

  1. Medvedev

    Medvedev Guest

    What's that preprocessor do
    #ifdef __cplusplus
    extern "C" {
    #endif
    ..
    ..
    ..
    #ifdef __cplusplus
    }
    #endif

    and how you say extern "C" , i mean how u extern constant!!
     
    Medvedev, Jul 6, 2008
    #1
    1. Advertising

  2. Medvedev

    Medvedev Guest

    On Jul 6, 2:12 pm, "Mike Wahler" <> wrote:
    > "Medvedev" <> wrote in message
    >
    > news:...
    >
    > > What's that preprocessor do
    > > #ifdef __cplusplus
    > > extern "C" {
    > > #endif
    > > .
    > > .
    > > .
    > > #ifdef __cplusplus
    > > }
    > > #endif

    >
    > > and how you say extern "C" , i mean how u extern constant!!

    >
    > extern "C"
    > {
    >
    > }
    >
    > .. causes any functions inside the braces to have
    > "C linkage", so that they can be called from C
    > functions. There's nothing about 'constant' here.


    sorry , but what differ C++ functions from C ones
     
    Medvedev, Jul 6, 2008
    #2
    1. Advertising

  3. Medvedev

    Jim Langston Guest

    "Medvedev" <> wrote in message
    news:...
    > On Jul 6, 2:12 pm, "Mike Wahler" <> wrote:
    >> "Medvedev" <> wrote in message
    >>
    >> news:...
    >>
    >> > What's that preprocessor do
    >> > #ifdef __cplusplus
    >> > extern "C" {
    >> > #endif
    >> > .
    >> > .
    >> > .
    >> > #ifdef __cplusplus
    >> > }
    >> > #endif

    >>
    >> > and how you say extern "C" , i mean how u extern constant!!

    >>
    >> extern "C"
    >> {
    >>
    >> }
    >>
    >> .. causes any functions inside the braces to have
    >> "C linkage", so that they can be called from C
    >> functions. There's nothing about 'constant' here.

    >
    > sorry , but what differ C++ functions from C ones


    C++ functions have overloading. C functions do not. This means there is
    only one definition for a C function, there can be more than one for a C++
    function. Compilers typcially handle this by "mangling". This will change
    the name of the C++ function in the object file so the linker can
    differentiate between calling parameters.

    stating:
    extern "C" {
    tells the compiler not to mangle the function names, there will only be one
    declaration for each function, so then when it is linked it has C linkage,
    the function name would be the same as if it was a C function, and C
    programs/objects can call the function as they can now link to them.
     
    Jim Langston, Jul 6, 2008
    #3
  4. Medvedev

    James Kanze Guest

    On Jul 7, 12:18 am, Medvedev <> wrote:
    > On Jul 6, 2:12 pm, "Mike Wahler" <> wrote:
    > > "Medvedev" <> wrote in message


    > >news:....


    > > > What's that preprocessor do
    > > > #ifdef __cplusplus
    > > > extern "C" {
    > > > #endif
    > > > .
    > > > .
    > > > .
    > > > #ifdef __cplusplus
    > > > }
    > > > #endif


    > > > and how you say extern "C" , i mean how u extern constant!!


    > > extern "C"
    > > {
    > > }


    > > .. causes any functions inside the braces to have
    > > "C linkage", so that they can be called from C
    > > functions. There's nothing about 'constant' here.


    > sorry , but what differ C++ functions from C ones


    Whatever the implementation wants. There's no fundamental
    reason for two different languages to use the same calling
    conventions. One typical difference might be that in C++, the
    call stack is cleaned up in the called function (since it
    involves calling destructors, etc.), where as in C, it is
    cleaned up in the callee (since historically, C didn't have
    prototypes, and allowed calling a function with extra arguments,
    which were ignored). Also, C++ has overloading, which means
    that some sort of information concerning the type and number of
    arguments must be maintained in the object file. And because C
    allowed extra arguments, a C compiler will not want to do this.

    --
    James Kanze (GABI Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
     
    James Kanze, Jul 7, 2008
    #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.
Similar Threads
  1. metfan
    Replies:
    2
    Views:
    4,864
    Robert Olofsson
    Oct 21, 2003
  2. Thomas Matthews
    Replies:
    5
    Views:
    2,484
    tom_usenet
    Aug 2, 2004
  3. newsock

    One extern usage

    newsock, Oct 22, 2003, in forum: C Programming
    Replies:
    3
    Views:
    641
    Dan Pop
    Oct 22, 2003
  4. sks
    Replies:
    3
    Views:
    415
  5. Andre
    Replies:
    5
    Views:
    550
    Keith Thompson
    Jul 17, 2012
Loading...

Share This Page