简体   繁体   English

由于“signed char”和“char”,系统头文件中的重定义错误

[英]redefinition error in system header file because of “signed char” and “char”

I try to include this file 我尝试包含这个文件

 boost/assign/list_of.hpp

but i have this compiler's error 但我有这个编译器的错误

/usr/include/boost/type_traits/is_integral.hpp:38: error: redefinition of struct boost::is_integral<char>
/usr/include/boost/type_traits/is_integral.hpp:32: error: previous  definition of  struct boost::is_integral<char>

these definitions lines (32,38) in file is_integral.hpp are: 文件is_integral.hpp中的这些定义行(32,38)是:

BOOST_TT_AUX_BOOL_TRAIT_CV_SPEC1(is_integral,signed char,true)
BOOST_TT_AUX_BOOL_TRAIT_CV_SPEC1(is_integral,char,true)

how to solve compile problem? 如何解决编译问题? the compiler is gcc version 4.4.7 20120313 OS is Red Hat Enterprise Linux Server release 6.5 (Santiago) 编译器是gcc版本4.4.7 20120313操作系统是红帽企业Linux服务器版本6.5(圣地亚哥)

From C++ standard 来自C ++标准

3.9.1 Fundamental types [basic.fundamental] 3.9.1基本类型[basic.fundamental]

Objects declared as characters (char) shall be large enough to store any member of the implementation's basic character set. 声明为字符(char)的对象应足够大,以存储实现的基本字符集的任何成员。 If a character from this set is stored in a character object, the integral value of that character object is equal to the value of the single character literal form of that character. 如果此组中的字符存储在字符对象中,则该字符对象的整数值等于该字符的单个字符文字形式的值。 It is implementation-defined whether a char object can hold negative values. 实现定义char对象是否可以保存负值。 Characters can be explicitly declared unsigned or signed. 字符可以显式声明为unsigned或signed。 Plain char, signed char, and unsigned char are three distinct types . Plain char,signed char和unsigned char是三种不同的类型 A char, a signed char, and an unsigned char occupy the same amount of storage and have the same alignment requirements (basic.types); char,signed char和unsigned char占用相同数量的存储空间并具有相同的对齐要求(basic.types); that is, they have the same object representation. 也就是说,它们具有相同的对象表示。 For character types, all bits of the object representation participate in the value representation. 对于字符类型,对象表示的所有位都参与值表示。 For unsigned character types, all possible bit patterns of the value representation represent numbers. 对于无符号字符类型,值表示的所有可能位模式表示数字。 These requirements do not hold for other types. 这些要求不适用于其他类型。 In any particular implementation, a plain char object can take on either the same values as a signed char or an unsigned char; 在任何特定实现中,普通char对象可以采用与signed char或unsigned char相同的值; which one is implementation-defined. 哪一个是实现定义的。

char , unsigned char and signed char are thus three distinct types and boost::is_integral should be specializable for those three types. charunsigned charsigned char是三种不同的类型, boost::is_integral应该适用于这三种类型。 One can expect gcc 4.4.7 or OP's environment to ignore that and I'll be looking for an explanation. 人们可以期待gcc 4.4.7或OP的环境忽略它,我会寻找解释。 Please see this temporary answer as an extended comment on OP's question. 请将此临时答案视为对OP问题的扩展评论。


EDIT : Cannot reproduce 编辑 :无法重现

System : Red Hat 6 系统 :Red Hat 6

$ uname -a
Linux ysc 2.6.32-504.8.1.el6.x86_64 #1 SMP Wed Jan 28 21:11:36 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux$

Compiler : 编译器

$ g++ --version
g++ (GCC) 4.4.7 20120313 (Red Hat 4.4.7-16)

Source : 来源

$ cat main.cpp

#include <iostream>

template<typename T>
struct trait
{
    static const int value = 0;
};

template<>
struct trait<char>
{
    static const int value = 1;
};

template<>
struct trait<signed char>
{
    static const int value = 2;
};

template<>
struct trait<unsigned char>
{
    static const int value = 3;
};

int main()
{
  std::cout << "int:, " << trait<int>::value << "!\n";
  std::cout << "char:, " << trait<char>::value << "!\n";
  std::cout << "unsigned char:, " << trait<unsigned char>::value << "!\n";
  std::cout << "signed char:, " << trait<signed char>::value << "!\n"; 
}

Compilation : 编译

$ g++ -Wall -Wextra main.cpp 

Run : 运行

$ ./a.out 
int:, 0!
char:, 1!
unsigned char:, 3!
signed char:, 2!

What does it produce on OP's environment? 它在OP的环境中产生了什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM