[FFmpeg-devel] Inhibit C++ name-mangling for FFmpeg public API

Stefano Sabatini stefano.sabatini-lala at poste.it
Thu Jun 23 19:04:42 CEST 2011


On date Thursday 2011-06-23 20:55:01 +0400, Kirill Gavrilov encoded:
> Hi,
> 
> many C-libraries follow C++ friendly style for their public headers and
> define constructions like this:
> /* Inhibit C++ name-mangling for libavutil functions */
> #ifdef __cplusplus
> extern "C" {
> #endif
> 
> ... library functions ...
> 
> #ifdef __cplusplus
> }
> #endif
> Such defines allows to include C-headers into C++ project without ugly
> declarations like that:
> extern "C" {
>    #include <libavutil/avutil.h>
> }
> This will simplify including FFmpeg in C++ projects and will eliminate
> common mistakes (especially by newbes).
> 
> Is it OK if I prepare the patch that will use this technique?
> Or there are some reasons (politics / religion) why these changes doesn't
> already included in FFmpeg project?

FFmpeg is meant to be a C project, adding partial support to C++ like
you suggested has the following disadvantages:
* gives the wrong impression that it is C++, while it isn't
* clutters the C code

Programmers working in a mixed C/C++ environment should be aware of
the differences between the two languages, also the need for using
extern will increase their awareness that they're not including C++
native headers, so they should take extra attention when dealing with
them, as a C++ programmer I tend to prefer that approach which I find
even cleaner.

And if you want to work with C++ maybe you should consider
using/writing a C++ wrapper/binding anyway, rather than rely on
half-baked C++ support implemented through clumsy ifdeffery.

And of course, yes this is politics/religion so you may disagree with
my position, nonetheless this looks like the position shared by most
devs here.
-- 
FFmpeg = Fascinating and Free Merciful Pitiless Emblematic Guru


More information about the ffmpeg-devel mailing list