Dealing with code redefining int types(uint16_t, int16_t, etc) and Boost not liking it

我们两清 提交于 2019-12-11 08:38:48

问题


So i am in a bit of stand off here and im not sure exactly how to go about proceeding, or if its even fixable...

We use a 3rd party SDK provided by another team, this SDK must be used for our app to function properly.

In this SDK, there are lines like this

#define uint16_t UINT16
#define uint8_t UINT8

The issue is in Boost, more specifically the ASIO/Details/cstdint.hpp file has lines that are

using std::uint16_t
using std::uint8_t

My app wont compile now because its really doing

using std::UINT16
using std::UINT8

And its complaining those types do not exist in std namespace obviously.

These UINT16 and UINT8 defines are used everywhere in the app that is very large, so replacing them is not very feasible, and im not even sure if the SDK would function if i did so.

I can try to #undef all of these defines before including the boost header files? And then redefine them after? Seems silly and i somehow doubt it would even work anyways.

Any advice?


回答1:


The issue is in Boost, more specifically the ASIO/Details/cstdint.hpp file has lines that are

That's upside down. The issue is clearly in the headers that redefine perfectly common typenames.

The most viable solution is to not include the SDK headers before you include any boost header, ever.

A patchwork workaround would be to undefine the macros. (Down that path lies madness, if you ask me):

#ifdef uint16_t
     #undef uint16_t
#endif


来源:https://stackoverflow.com/questions/49614169/dealing-with-code-redefining-int-typesuint16-t-int16-t-etc-and-boost-not-lik

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!