简体   繁体   English

Ubuntu 中的“int”

[英]“int” in Ubuntu

Can anyone tell me if, when compiling a c++ program, does g++ (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5 change int s to long int s?谁能告诉我,在编译 c++ 程序时,g++ (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5 是否将int s 更改为long int s? if so, how can this be changed?如果是这样,如何改变? If not, do I just overload operator long ?如果没有,我是否只是重载operator long Is it just like overloading operator uint32_t/uint64_t?是不是就像重载运算符 uint32_t/uint64_t 一样? It seems like a different type of typecasting (no pun intended).这似乎是一种不同类型的类型转换(不是双关语)。

this is causing the errors:导致错误:

uint128_t.h: In function ‘std::ostream& operator<<(std::ostream&,
uint128_t)’:
uint128_t.h:593: error: conversion from ‘uint128_t’ to ‘long int’ is
ambiguous
uint128_t.h:83: note: candidates are: uint128_t::operator uint64_t()
uint128_t.h:79: note:                 uint128_t::operator uint32_t()
uint128_t.h:75: note:                 uint128_t::operator uint16_t()
uint128_t.h:71: note:                 uint128_t::operator uint8_t()
uint128_t.h:67: note:                 uint128_t::operator int()
uint128_t.h:63: note:                 uint128_t::operator char()
uint128_t.h:59: note:                 uint128_t::operator bool()

No, it doesn't.不,它没有。 An int is an int is an int.一个 int 是一个 int 是一个 int。 It's a separate type from long int .它是与long int不同的类型。 As for which operators you overload, it depends entirely on what you want to do .至于你重载哪些算子,完全看你想做什么 You haven't really described that.你还没有真正描述过。

But if you want to define an operator to work on int , then you should overload it for int .但是如果你想定义一个操作符来处理int ,那么你应该为int重载它。 If you want it to work on long int , define an overload for that.如果您希望它在long int上工作,请为此定义一个重载。

What are you trying to do?你想做什么? And why are you passing a uint128_t to the operator, but asking about int and long int ?为什么你将uint128_t传递给操作员,但询问intlong int

Try this variation:试试这个变化:

out = "0123456789abcdef"[size_t(rhs % div)] + out;

since you've provided conversions to all manner of unsigned types, but not to signed int.因为您提供了对各种无符号类型的转换,但没有提供对有符号整数的转换。


And yes, you can define an implicit conversion to long int just be defining operator long in the same manner as all the other conversions.是的,您可以定义到long int的隐式转换,只需以与所有其他转换相同的方式定义operator long


Finally, please note that your choice of structure name is reserved by POSIX, and likely to conflict with future versions of the standard library header stdint.h .最后,请注意,您选择的结构名称由 POSIX 保留,并且可能与标准库 header stdint.h的未来版本冲突。

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

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