Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Does the typedef definition matter inside a extern "C" declration

Reply
Thread Tools

Does the typedef definition matter inside a extern "C" declration

 
 
parag_paul@hotmail.com
Guest
Posts: n/a
 
      06-11-2008
Does the following typedef differ from a typedef inside a extern "C"


#if defined(__cplusplus)
extern "C" {
#endif


typedef int (*fun_point)(int);

#if defined(__cplusplus)
}
#endif



then a plain typedef
 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      06-11-2008
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Does the following typedef differ from a typedef inside a extern "C"
>
>
> #if defined(__cplusplus)
> extern "C" {
> #endif
>
>
> typedef int (*fun_point)(int);
>
> #if defined(__cplusplus)
> }
> #endif
>

Yes, the above is idiomatic for headers files shared between C and C++.

>
> then a plain typedef


I'm not sure what you mean by this. In the example above, fun_point is
a pointer to a C linkage function.

If the typedef wasn't wrapped with extern "C", fun_point would be a
pointer to a C++ free function.

--
Ian Collins.
 
Reply With Quote
 
 
 
 
parag_paul@hotmail.com
Guest
Posts: n/a
 
      06-11-2008
On Jun 11, 2:30*pm, Ian Collins <(E-Mail Removed)> wrote:
> (E-Mail Removed) wrote:
> > Does the following typedef differ from a typedef inside a extern "C"

>
> > #if defined(__cplusplus)
> > extern "C" {
> > #endif

>
> > typedef (*fun_point)(int);

>
> > #if defined(__cplusplus)
> > }
> > #endif

>
> Yes, the above is idiomatic for headers files shared between C and C++.
>
>
>
> > then a plain typedef

>
> I'm not sure what you mean by this. *In the example above, fun_point is
> a pointer to a C linkage function.
>
> If the typedef wasn't wrapped with extern "C", fun_point would be a
> pointer to a C++ free function.
>
> --
> Ian Collin


since I used fun_point in the prototype and in teh definition I used
the int (*fun_point)(int)
and it was complaining of anachronism
 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      06-12-2008
On Jun 11, 4:23 pm, "(E-Mail Removed)" <(E-Mail Removed)>
wrote:
> On Jun 11, 2:30 pm, Ian Collins <(E-Mail Removed)> wrote:
> > (E-Mail Removed) wrote:
> > > Does the following typedef differ from a typedef inside a
> > > extern "C"


> > > #if defined(__cplusplus)
> > > extern "C" {
> > > #endif


> > > typedef (*fun_point)(int);


> > > #if defined(__cplusplus)
> > > }
> > > #endif


> > Yes, the above is idiomatic for headers files shared between
> > C and C++.


> > > then a plain typedef


> > I'm not sure what you mean by this. In the example above, fun_point is
> > a pointer to a C linkage function.


> > If the typedef wasn't wrapped with extern "C", fun_point would be a
> > pointer to a C++ free function.


> since I used fun_point in the prototype and in teh definition I used
> the int (*fun_point)(int)
> and it was complaining of anachronism


To clarify what Ian said, given:

extern "C" {
typedef void (*fp1)( int ) ;
}
typedef void (*fp2)( int ) ;

fp1 and fp2 are two different, unrelated types. You cannot use
one for the other; if you do, the compiler is required to emit a
diagnostic. (Some compilers have errors in this regard.)

--
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
can a class definition inside another class's definition Jianli Shen C++ 1 03-13-2005 06:02 PM
extern const char * vs. extern const char []http://tinyurl.com/47e3k Thomas Matthews C++ 5 08-02-2004 10:36 AM
class declration one2001boy@yahoo.com C++ 2 07-25-2004 12:41 PM
Whattsa Matter, Dark Matter?? A.Melon DVD Video 0 05-16-2004 07:05 AM



Advertisments