[MPlayer-dev-eng] Exporting functions and types
savignien hercule
savignien at caramail.com
Wed Sep 24 11:05:40 CEST 2003
1. Sorry for the html...
2. extern is not "useless". It's the default class for functions. That's why
you don't need to use it explicitly.
My goal with the "hack" I propose is :
- Be clear about the types and functions wich are exported : they are in the .h file
and nowhere else.
- Declare things only once so if you modify them you do the job one time.
Note that my "hack", as you call it, works also for global variables, so if only for that
it may be a good idea no ?
Savi.
------- Message d'origine -------
De: D Richard Felker III <dalias at aerifal.cx>
Date: Tue, 23 Sep 2003 15:38:44 -0400
Sujet: Re: [MPlayer-dev-eng] Exporting functions and types
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
> .. /* 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
Plus simple, plus fiable, plus rapide : découvrez le nouveau Caramail - http://www.caramail.lycos.fr
More information about the MPlayer-dev-eng
mailing list