[MPlayer-dev-eng] Exporting functions and types
D Richard Felker III
dalias at aerifal.cx
Tue Sep 23 21:38:44 CEST 2003
On Tue, Sep 23, 2003 at 04:15:42PM +0100, savignien hercule wrote:
> table.mail_content {DISPLAY: block}
>
> Well the problem appeared when I tried to compile the subrip tool of
> mplayer. This tools needs an spudec_handle_t type to work. The original
> type is defined in spudec.c file.If you #include the spudec.c file in
> subrip.c, it doesn't compile because of others type. Even in moving the
> spudec_handle_t declaration in the spudec.h file it didn't work. In fact,
> it's not very easy to reuse a function or a type defined somewhere in
> the mplayer sources. So I suggest a way to export cleanly functions and
> types : In the file foo.c : /* System includes */ #include <stdio.h>
> .. /* foo.h include */ #define FOO_C #include "foo.h" #undef FOO_C /*
> other includes */ .. /* static types and functions */ .. /* code */
> In the file foo.h : #ifndef FOO_H #define FOO_H #ifndef FOO_C #define
> EXTERN_FOO extern #else #define EXTERN_FOO #endif /* exported types */
> typedef t1 ... /* exported functions */ EXTERN_FOO f1( ...); EXTERN_FOO
> f2( ...); .. #undef EXTERN_FOO #endif /* FOO_H */ This way, whoever
> needs the f1 or f2 function or t1 type just has to include foo.h et link
> with foo.o. Well I realise what a work applying this to mplayer would be,
> but it can be made each time a .c file is modified...
> Hope, this will help...
> Savi.
> PS: I succeded in compiling subrip. It works fine. I plan to submit the
> modifications of this tool soon.
A couple comments...
1, please don't send misformatted html mail (or better yet don't send
html mail at all). The above is what it came out as for me!
2, you don't need hacks like this, you just need to learn C. extern is
useless with function declarations/prototypes and only needed for
accessing global variables, AND it's valid to declare a variable
extern in foo.h and then have the real declaration in foo.c even if
foo.c includes foo.h.
Rich
More information about the MPlayer-dev-eng
mailing list