visual studio 2008 error C2371: 'int8_t' : redefinition; different basic types (http_parser.h)

久未见 提交于 2020-01-22 16:28:12

问题


i try to compile simple c/c++ app that is using http_parser from node.js i also using libuv , and basically trying to compile this example in windows. using visual studio 2008

but i getting this compilation error :

>d:\dev\cpp\servers\libuv\libuv_http_server\http_parser.h(35) : error C2371: 'int8_t' : redefinition; different basic types
1>        d:\dev\cpp\servers\libuv\libuv-master\libuv-master\include\uv-private\stdint-msvc2008.h(82) : see declaration of 'int8_t'

the code in the http_parser.h file looks like this:

#include <sys/types.h>
#if defined(_WIN32) && !defined(__MINGW32__) && (!defined(_MSC_VER) || _MSC_VER<1600)
#include <BaseTsd.h>
#include <stddef.h>
//#undef __int8
typedef __int8 int8_t;
typedef unsigned __int8 uint8_t;
typedef __int16 int16_t;
typedef unsigned __int16 uint16_t;
typedef __int32 int32_t;
typedef unsigned __int32 uint32_t;
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
#else
#include <stdint.h>
#endif

as you can see i tryed to undef it but it didnt worked. what can i do so it will pass compilation . if i just remove it im getting this error :

http_parser.c(180) : error C2061: syntax error : identifier 'unhex'

on this code section :

static const int8_t unhex[256] =
  {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
  ,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
  ,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
  , 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,-1,-1,-1,-1,-1,-1
  ,-1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1
  ,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
  ,-1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1
  ,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
  };

and many other sections that using int8_t


回答1:


As it's a typedef, you can't use #ifdef or #undef etc, because these only work with symbols that have been #define'ed.

The best you can do is to make sure that the two typedef's agree, the there should be no problem.

Looking at stdint-msvc2008.h, it might be easier to modify http_parser.h to this:

typedef signed __int8 int8_t;

Any good?



来源:https://stackoverflow.com/questions/16415058/visual-studio-2008-error-c2371-int8-t-redefinition-different-basic-types

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