[dpdk-dev] [PATCH] eal: standard c++ forbids defining the keyword asm as a macro

Thomas Monjalon thomas at monjalon.net
Wed Mar 24 18:04:08 CET 2021


24/03/2021 17:45, Tyler Retzlaff:
> On Wed, Mar 24, 2021 at 09:30:58AM +0100, Thomas Monjalon wrote:
> > 24/03/2021 05:26, Tyler Retzlaff:
> > > +#ifndef __cplusplus
> > >  #ifndef asm
> > >  #define asm __asm__
> > >  #endif
> > > +#endif
> > 
> > It requires more explanations.
> > Which compilers do not define asm?
> > What happens with C++ if asm is undefined?
> 
> i guess the subject line on my commit didn't communicate this properly
> sorry.
> 
> asm is a keyword in both the C and C++ standards. for C++ the keyword is
> not permitted to be re-defined.
> 
> here is the relevant text from the standard, in particular item (2).
> 
>   17.6.4.3.1 Macro names [macro.names]
> 
>   1
>   A translation unit that includes a standard library header shall not
>   #define or #undef names declared in any standard library header.
> 
>   2
>   A translation unit shall not #define or #undef names lexically identical
>   to keywords, to the identifiers listed in Table 3, or to the attribute-tokens
>   described in 7.6.
> 
> so when including rte_common.h into a translation unit that is being
> compiled C++ the rte_common.h violates the standard by leaking the
> #define asm macro.
> 
> this problem appears as soon as you try to build a C++ based dpdk
> application with clang using windows C++ runtime and #include <list>.

I understood this part.

My question is more about the reason for having this define.
I think it is there because some compilers don't have asm keyword,
but have __asm__. And maybe that's the case for some C++ compilers.
If I'm right, this patch is breaking compilation with some
C++ compilers.




More information about the dev mailing list