[FFmpeg-devel] Moving if(constant expression) to preprocessor?
Sat Sep 18 18:41:26 CEST 2010
M?ns Rullg?rd wrote:
> "Axel Holzinger" <aholzinger at gmx.de> writes:
> > Hi M?ns and all,
> > M?ns Rullg?rd wrote:
> >> "Axel Holzinger" <aholzinger at gmx.de> writes:
> >> > Hi all,
> >> >
> >> > if compiling FFmpeg code with zero optimisations (even
> >> > without dead code elimination) there are linker errors
> >> > (undefined references to
> >> > functions or structs) that come from constructs like i.e.
> >> > the following in libavcodec/allcodecs.c:
> >> >
> >> > if(CONFIG_##X##_HWACCEL) av_register_hwaccel(&x##_hwaccel); }
> >> >
> >> > The runtime (lower case) "if" leads to an undefined reference,
> >> > because it is evaluated at runtime and not at compile time.
> >> >
> >> > If dead code eliminitation optimisation is on, this isn't an
> >> > issue, but with optimisations completely off it is.
> >> Don't do that then.
> > Hehe, if we all would be so shy, we would still live in caves,
> > wouldn't we :-)
> This is the first time I have seen FFmpeg referred to as shy.
For everything there's a first time.
> >> > Is there interest in doing this in a way where already the
> >> > preprocessor is solving this (instead of the optimiser)?
> >> No.
> > Ah.
> >> > Then I would try and find a solution based on preprocessor
> >> That is not easily possible.
> > Says who ;-)
> Says I.
And that has to suffice?
> > You could leave this up to me or others.
> > It is possible to write a macro that does the trick and in
> > the end the above line would for example look like this:
> > AV_COND_IF(CONFIG_##X##_HWACCEL,
> How would AV_COND_IF be defined?
Do you know boost?
They have a really nice preprocessor library. I got inspired by their
It's more generic as it would be needed here. So reduced to what's
needed it could look like this (compiler specific #fdefs removed for
# define ICL_PP_IF(cond, t, f) ICL_PP_IF_I(cond, t, f)
# define ICL_PP_IF_I(cond, t, f) ICL_PP_IIF(ICL_PP_BOOL(cond), t, f)
#define AV_COND_IF(bit, t, f) AV_COND_IF_OO((bit, t, f))
#define AV_COND_IF_OO(par) AV_COND_IF_I ## par
#define AV_COND_IF_I(bit, t, f) AV_COND_IF_I(AV_COND_IIF_ ## bit(t,
#define AV_COND_IF_I(id) id
#define AV_COND_IF_0(t, f) f
#define AV_COND_IF_1(t, f) t
Isn't that sexy?
> > Wouldn't that still be fine? And it could be done with a
> > few lines of generic macro defintions that could go to some
> > generic header.
> > What would be the disadvantage?
> It wouldn't work.
Come on, don't be shy :-)
More information about the ffmpeg-devel