* extern c in cpp file`
@ 2003-11-26 19:32 y2bismil
2003-11-26 19:59 ` Eljay Love-Jensen
0 siblings, 1 reply; 3+ messages in thread
From: y2bismil @ 2003-11-26 19:32 UTC (permalink / raw)
To: gcc-help
Hi all,
I was wondering what the consequences were (if any) of declaring a function as
extern "C" in a header file, and then implementing it in a cpp module. It seems
to compile file, but I was wondering if there are any unintended consequences?
Thanks,
Yamin
----------------------------------------
This mail sent through www.mywaterloo.ca
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: extern c in cpp file`
2003-11-26 19:32 extern c in cpp file` y2bismil
@ 2003-11-26 19:59 ` Eljay Love-Jensen
2003-11-28 16:51 ` Nathan Sidwell
0 siblings, 1 reply; 3+ messages in thread
From: Eljay Love-Jensen @ 2003-11-26 19:59 UTC (permalink / raw)
To: y2bismil, gcc-help
Hi Yamin,
The consequences of declaring a function as extern "C" are...
1) the name will be mangled according to your platform's C mangling convention*.
2) I recall (and I may be mistaken) that such a function acts as a "C barrier", and thus exceptions do not propagate through such a function.
Merely specifying the header declaration (prototype) as an extern "C" is good enough for the translation unit's definition (implementation) to use the C specification.
HTH,
--Eljay
* some C mangling conventions (depending on platform)...
1) convert to uppercase (ala Pascal)
2) prefix a leading underscore
3) leave the identifier as given.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: extern c in cpp file`
2003-11-26 19:59 ` Eljay Love-Jensen
@ 2003-11-28 16:51 ` Nathan Sidwell
0 siblings, 0 replies; 3+ messages in thread
From: Nathan Sidwell @ 2003-11-28 16:51 UTC (permalink / raw)
To: Eljay Love-Jensen; +Cc: y2bismil, gcc-help
Eljay Love-Jensen wrote:
> Hi Yamin,
>
> The consequences of declaring a function as extern "C" are...
>
> 1) the name will be mangled according to your platform's C mangling convention*.
> 2) I recall (and I may be mistaken) that such a function acts as a "C barrier", and thus exceptions do not propagate through such a function.
you are mistaken. when compiled by a C++ compiler, you'll get all the C++
exception semantics. When compiled by a C compiler, you might or might not
get unwind info emitted (with gcc -fexceptions, you will IIRC).
nathan
--
Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
The voices in my head said this was stupid too
nathan@codesourcery.com :: http://www.planetfall.pwp.blueyonder.co.uk
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2003-11-28 16:51 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-11-26 19:32 extern c in cpp file` y2bismil
2003-11-26 19:59 ` Eljay Love-Jensen
2003-11-28 16:51 ` Nathan Sidwell
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 read-only IMAP folder(s) and NNTP newsgroup(s).