Re: [PATCH rdma-core] verbs: Fix C++ compilation break

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Oct 09, 2017 at 09:41:04AM -0600, Jason Gunthorpe wrote:
> On Mon, Oct 09, 2017 at 11:17:17AM +0300, Leon Romanovsky wrote:
> > From: Leon Romanovsky <leonro@xxxxxxxxxxxx>
> >
> > The commit 983f80191923 ("verbs: fix compilation error with ICC") fixed
> > warning by using UINTPTR_MAX, however such change breaks compilation
> > of C++ applications.
> >
> > In C++ world, the UINTPTR_MAX is declared in <cstdint> and not stdint.h,
> > so in order to avoid messing with various defines to decide which
> > header
>
> I don't think this statement is right. In C++ land the 'cXXX' headers
> and the 'XXX.h' headers are usually the same.

Most of the time, it is true, but stdint.h is different and it is
different between C99 and C++11.

> On my system I see
> nothing that would cause stdint.h to not define the macros in C++ mode:
>
> $ echo t.cc
> #include <stdint.h>
>
> enum {foo = UINTPTR_MAX};
>
> $ g++-5 -c -Wall t.cc
>
> So, what environment fails here? It should be described in the
> commit message..

It means that your glibc is new enough.
On some systems, the stdint.h contains the following ifdef to protect UINTPTR_MAX
"#if !defined __cplusplus || defined __STDC_LIMIT_MACROS"

>
> The best fix is something like this:
>
> #ifdef __cplusplus
> #include <limits>
> #define __VERBS_ABI_IS_EXTENDED ((void *)std::numeric_limits<uintptr_t>::max())
> #else
> #define __VERBS_ABI_IS_EXTENDED ((void *)UINTPTR_MAX)
> #endif
>
> The static in a header file also a mistake.
>
> Using <cstdint> is a bit risky since it is a c++11 header and may not
> be in some of the older distros we still support.
>
> Jason

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Yosemite Photos]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux