On 8/1/05, avinash pawar <[EMAIL PROTECTED]> 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
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" 
in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to