Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to workaround a #define introduced by a vendor?

Tags:

c++

c

c++11

So, a vendor that we use has provided a library (primarily for C, with some C++ support) that does the following:

#ifndef int64_t
#define int64_t s_int64
#endif
#ifndef int32_t
#define int32_t s_int32
#endif
#ifndef int16_t
#define int16_t s_int16
#endif
#ifndef int8_t
#define int8_t  s_int8
#endif

In one of their headers deep inside their library. Now the problem is that once their library is included in simple C++11 code such as:

#include <iostream>

#include <vendor/library.h>

int main(void)
{
  std::int32_t std_i = 0;
  return std_i;
}

There is immediately a compiler error, (s_int32 is not in std::). So question is, short of nagging the vendor to this fix this, is there anyway to workaround this in our code? (btw. things that I have tried, #include <cstdint> before their headers, no luck; extern "C" wrapper, no luck. The headers are installed in /usr/include/ so no control over order of inclusion I guess as well...)

like image 838
Nim Avatar asked Nov 28 '22 09:11

Nim


1 Answers

You can undefine their definitions.

#undef int64_t
#undef int32_t
#undef int16_t
#undef int8_t
like image 78
Ivan Ishchenko Avatar answered Mar 16 '23 20:03

Ivan Ishchenko