469,282 Members | 1,892 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

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

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
Jun 27 '08 #1
3 1495
pa********@hotmail.com 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.
Jun 27 '08 #2
On Jun 11, 2:30*pm, Ian Collins <ian-n...@hotmail.comwrote:
parag_p...@hotmail.com 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
Jun 27 '08 #3
On Jun 11, 4:23 pm, "parag_p...@hotmail.com" <parag_p...@hotmail.com>
wrote:
On Jun 11, 2:30 pm, Ian Collins <ian-n...@hotmail.comwrote:
parag_p...@hotmail.com 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:ja*********@gmail.com
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
Jun 27 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

43 posts views Thread by steve | last post: by
5 posts views Thread by Kai Grossjohann | last post: by
4 posts views Thread by Christian Christmann | last post: by
10 posts views Thread by Mark A. Gibbs | last post: by
7 posts views Thread by binary-nomad | last post: by
10 posts views Thread by Pantokrator | last post: by
51 posts views Thread by Tony Sinclair | last post: by
8 posts views Thread by Ulysse | last post: by
2 posts views Thread by Angus | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.