Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > extern "c" usage?!!

Reply
Thread Tools

extern "c" usage?!!

 
 
Medvedev
Guest
Posts: n/a
 
      07-06-2008
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!!
 
Reply With Quote
 
 
 
 
Medvedev
Guest
Posts: n/a
 
      07-06-2008
On Jul 6, 2:12 pm, "Mike Wahler" <(E-Mail Removed)> wrote:
> "Medvedev" <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed)...
>
> > 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
 
Reply With Quote
 
 
 
 
Jim Langston
Guest
Posts: n/a
 
      07-06-2008
"Medvedev" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On Jul 6, 2:12 pm, "Mike Wahler" <(E-Mail Removed)> wrote:
>> "Medvedev" <(E-Mail Removed)> wrote in message
>>
>> news:(E-Mail Removed)...
>>
>> > 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.


 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      07-07-2008
On Jul 7, 12:18 am, Medvedev <(E-Mail Removed)> wrote:
> On Jul 6, 2:12 pm, "Mike Wahler" <(E-Mail Removed)> wrote:
> > "Medvedev" <(E-Mail Removed)> wrote in message


> >news:(E-Mail Removed)....


> > > 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:(E-Mail Removed)
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference of extern short *x and extern short x[]? Andre C Programming 5 07-17-2012 07:38 PM
extern const char * vs. extern const char []http://tinyurl.com/47e3k Thomas Matthews C++ 5 08-02-2004 10:36 AM
Re: extern function declaration josef angermeier C++ 0 07-17-2003 08:31 AM
Re: extern function declaration Andrey Tarasevich C++ 0 07-16-2003 06:51 PM
char s[] = "asdf" and extern char *s in separate files Newsgroup - Ann C++ 1 07-05-2003 06:34 AM



Advertisments