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

P

parag_paul

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
 
I

Ian Collins

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.
 
P

parag_paul

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




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
 
J

James Kanze

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.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top