From: Steve Graegert <graegerts@gmail.com>
To: avinash pawar <lkmails@gmail.com>
Cc: linux-c-programming@vger.kernel.org
Subject: Re: Query in C
Date: Mon, 1 Aug 2005 08:44:25 +0200 [thread overview]
Message-ID: <6a00c8d5050731234411b2bbaa@mail.gmail.com> (raw)
In-Reply-To: <d5b9712e05073123104617be93@mail.gmail.com>
On 8/1/05, avinash pawar <lkmails@gmail.com> wrote:
> Hello Everyone ,
>
> Can anyone of you please tell me..
>
> what does extern "C" int func(int *,foo) accomplish ?
>
When using existing C headers that already conform to ANSI C in C++
they need to be slightly modified to enable proper linkage for the
language and to ensure that C++ keywords are not used as identifiers.
This means that you can use C headers in C++ projects in the following way:
#ifdef __cplusplus
extern "C" {
#endif
...
int func(int *,foo);
...
#ifdef __cplusplus
}
#endif
Code placed between the two ifdefs is either linked as C or C++. The
__cplusplus macro is usually predefined in appropriate system headers.
To answer your question: when a routine will be called from another
language (here C is called from C++) it should be declared in C++ as
extern "C" int func(int *,foo);
The extern "C" causes the routine to have a so called 'unmangled' name
that can be refered to not only from C but also from Fortran or Cobol.
Without extern "C" the routine will get a link 'mangled' link name
like func__abc.
Regards
\Steve
--
Steve Graegert
Software Consultancy
Mobile: +49 (176) 21248869
Office: +49 (9131) 7126409
next prev parent reply other threads:[~2005-08-01 6:44 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-07-15 14:02 Variable to sizeof function Vikas S
2005-07-15 15:00 ` Vadiraj
2005-07-15 15:16 ` Rechberger Markus
2005-07-15 17:53 ` Vikas S
2005-07-15 22:35 ` Steve Graegert
2005-07-16 6:44 ` Vikas S
2005-07-16 7:04 ` Steve Graegert
2005-07-16 8:26 ` Steven Smith
2005-07-16 14:30 ` Eric Bambach
2005-07-17 16:27 ` Vadiraj
2005-08-01 6:10 ` Query in C avinash pawar
2005-08-01 6:44 ` Steve Graegert [this message]
-- strict thread matches above, loose matches on Subject: below --
2005-08-01 11:13 r_zaca
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6a00c8d5050731234411b2bbaa@mail.gmail.com \
--to=graegerts@gmail.com \
--cc=linux-c-programming@vger.kernel.org \
--cc=lkmails@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).