what dose it mean?

Discussion in 'C++' started by snnn, Jan 22, 2005.

  1. snnn

    snnn Guest

    ///////////////////////
    #ifdef __cplusplus
    extern "C" {
    #endif
    ////////////////////////
    I often find it at c/c++ head files.
     
    snnn, Jan 22, 2005
    #1
    1. Advertising

  2. snnn

    Efrat Regev Guest

    1. This has to do "name mangling" explained below, and
    2. It is used for "connecting" C and C++ code, so that your project can
    include both.

    Suppose you write a method named "foobar". When your compiler turns your
    code into an executable, it doesn't have to retain the *name* foobar; it can
    change it let's say into "shmilky", as long everyone else knows that
    "shmilky" really means the method you called "foobar". As a *user* of the
    compiler, you usually shouldn't have to care about this.

    Why would your compiler do that in the first place? probably not much of
    an issue if you're not writing a compiler (check name mangling in Google, if
    you're interested).
    Why the extern "C", then? C and C++ are different languages, and would
    understand "shmilky" differently. The extern "C" causes both of them to
    understand that "shmilky" stands for "foobar" (which is what you want).

    "snnn" <> wrote in message
    news:...
    > ///////////////////////
    > #ifdef __cplusplus
    > extern "C" {
    > #endif
    > ////////////////////////
    > I often find it at c/c++ head files.
    >
    >
     
    Efrat Regev, Jan 22, 2005
    #2
    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. al
    Replies:
    3
    Views:
    2,708
  2. kent
    Replies:
    1
    Views:
    369
    James David Miller
    Apr 1, 2004
  3. Replies:
    1
    Views:
    319
  4. s88
    Replies:
    2
    Views:
    922
  5. Car
    Replies:
    3
    Views:
    3,430
    Richard Bos
    Feb 28, 2008
Loading...

Share This Page