[dpdk-dev] [RFC 10/35] eal: introduce RTE_DECONST macro
Stephen Hemminger
stephen at networkplumber.org
Wed Mar 9 19:53:17 CET 2016
Can't we just write correct code rather than trying to trick the compiler.
On Wed, Mar 9, 2016 at 8:19 AM, Olivier Matz <olivier.matz at 6wind.com> wrote:
> This macro removes the const attribute of a variable. It must be used
> with care in specific situations. It's better to use this macro instead
> of a manual cast, as it explicitly shows the intention of the developer.
>
> This macro is used in the next commit of the series.
>
> Signed-off-by: Olivier Matz <olivier.matz at 6wind.com>
> ---
> lib/librte_eal/common/include/rte_common.h | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git a/lib/librte_eal/common/include/rte_common.h
> b/lib/librte_eal/common/include/rte_common.h
> index 332f2a4..dc0fc83 100644
> --- a/lib/librte_eal/common/include/rte_common.h
> +++ b/lib/librte_eal/common/include/rte_common.h
> @@ -285,6 +285,15 @@ rte_align64pow2(uint64_t v)
>
> /*********** Other general functions / macros ********/
>
> +/**
> + * Remove the const attribute of a variable
> + *
> + * This must be used with care in specific situations. It's better to
> + * use this macro instead of a manual cast, as it explicitly shows the
> + * intention of the developer.
> + */
> +#define RTE_DECONST(type, var) ((type)(uintptr_t)(const void *)(var))
> +
> #ifdef __SSE2__
> #include <emmintrin.h>
> /**
> --
> 2.1.4
>
>
More information about the dev
mailing list