[FFmpeg-devel] [PATCH 01/15] avutil/common: Add macro for left-shifting

Michael Niedermayer michael at niedermayer.cc
Thu Sep 26 10:38:56 EEST 2019


On Wed, Sep 25, 2019 at 12:02:56AM +0200, Andreas Rheinhardt wrote:
> Left shifting a negative integer is undefined, yet often needed.
> Therefore add a macro that internally uses multiplication by powers of
> two to make it clear that a shift is intended.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
> ---
> I don't insist on this macro. I only added it so that one can easily see
> that shifting was intended. I initially wanted to use "FFLS", but
> eventually chose FFLSHIFT because it is self-explanatory.
> 
>  libavutil/common.h | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/libavutil/common.h b/libavutil/common.h
> index af35397eb9..93c5dd0af7 100644
> --- a/libavutil/common.h
> +++ b/libavutil/common.h
> @@ -60,6 +60,14 @@
>  /* Backwards compat. */
>  #define FF_CEIL_RSHIFT AV_CEIL_RSHIFT
>  
> +/**
> + * Left shift macro designed to tackle the undefinedness
> + * of left-shifting negative numbers.
> + *
> + * Note: Still undefined if the multiplication overflows.
> + */
> +#define FFLSHIFT(a,b) ((a) * (1 << (b)))

with 
a * (1 << b)
everyone knows what it does even if one doesnt know why its done that way

with 
FFLSHIFT(a, b)
only people who looked up the macro know what it does and why.

so iam a bit sceptic that this is a good idea.

thx

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

In fact, the RIAA has been known to suggest that students drop out
of college or go to community college in order to be able to afford
settlements. -- The RIAA
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20190926/c9e3948d/attachment.sig>


More information about the ffmpeg-devel mailing list