- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
这个问题应该是给语言律师的。
假设 signed 和 unsigned int 都是 32 位宽。如 n3337.pdf 草案 5.3.1.8 所述,
(-(0x80000000u)) = 0x100000000u-0x80000000u = 0x80000000u
但我找不到问题的答案:signed 0x80000000 的一元减号是什么?是 UB、实现定义还是...?
问题主要是关于运行时计算。
说
signed int my_minus(signed int i) { return -i;}
....
int main() {
signed int a = -0x7FFFFFFF; // a looks like 0x80000001
signed int b = a - 1; // b looks like 0x80000000
std::cout << my_minus(b);
....
}
不过,欢迎您对其他 2 个案例发表评论:
编译时常量折叠,比如 -(INT_MIN)
constexpr
的编译时计算(如果与编译时常量折叠有区别)。
(请在重复投票前查看https://meta.stackexchange.com/questions/123713/is-splitting-a-question-a-good-practice。)
最佳答案
据我所知,有符号整数溢出总是未定义的。来自 C++ 规范部分 5 Expressions,第 4 段:
If during the evaluation of an expression, the result is not mathematically defined or not in the range of representable values for its type, the behavior is undefined. [Note: most existing implementations of C++ ignore integer overflows. Treatment of division by zero, forming a remainder using a zero divisor, and all floating point exceptions vary among machines, and is usually adjustable by a library function. —endnote]
关于c++ 只有 : unary minus for 0x80000000,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9476036/
[over.unary]/2 The unary and binary forms of the same operator are considered to have the same name.
这里是this link它说: The static_cast keyword can be used for any normal conversion between types. Convers
公式开头的两个 - 符号是什么意思? 例如:此公式获取字符串日期并将其转换为 Excel 日期序列号: =--(MID(S2,4,3)&LEFT(S2,3)&MID(S2,7,4)) 公式运行正常,我
我正在尝试将 php 算法移植到 perl,但我在使用我不熟悉的一位运算符时遇到了困难... 所以 php 代码看起来像这样: ... $var = '348492634'; print ~$var;
很抱歉重复这个问题,但我无法理解(我认为我的问题是)指针。有人可以帮我解释一下吗?我已经浏览了大量的 stackoverflow 问题、c 教程,而且它最令人困惑,因为每个解决方案似乎都与另一个解决方
我正在尝试读取包含以下内容的文本文件 sport.txt,并尝试将用户输入与文本文件中找到的运动名称相匹配。 如果找到它会打印“找到运动”,如果没有找到它会打印“找不到运动”。 显示的第一个示例看起来
我写的 Bash 不多,所以我对如何解决这个问题有点困惑。我需要检查命令返回的值是否大于 x。当它运行时,我得到了 [: -gt: unary operator expected 我无法修复。 这是我
我正在编写一个简单的代码,输出目录中以 00 开头的子目录的数量。这是我的代码: #!/bin/bash maxout=2 function getnumber { number=`ls |
#!/bin/bash export PROCNAME=test export TABLE_ID=0 if [ ${TABLE_ID} -eq "" ]; then echo h
以下代码片段在我的工作系统中运行,同样的代码在我的 PC 中抛出错误。 std::bitset my_bit(*(uint32_t*)&(OFDM_cod[V][a/8].real())); Erro
我在玩codewar,我赢不了这个挑战。链接在这里: http://www.codewars.com/kata/54ca3e777120b56cb6000710/train/python 这是我的实现
我在第 5 行和第 11 行收到错误一元运算符。请帮助解决这个问题。 echo ”enter the number” read n q=$n a=0 while [ $q – gt 0 ] do
C++ 标准库提供了将比较器传递给 std::sort 的功能.但是,我的代码中有很多情况需要对 T 的列表进行排序。函数对象f .像这样的比较器将是一个有效的选择: bool compare(con
这个问题应该是给语言律师的。 假设 signed 和 unsigned int 都是 32 位宽。如 n3337.pdf 草案 5.3.1.8 所述, (-(0x80000000u)) = 0x100
鉴于 a 是未定义的,下面看起来不错: a + b + blah # => NameError: undefined local variable or method `a' for main:Obj
给定 Ruby 代码 line = "first_name=mickey;last_name=mouse;country=usa" record = Hash[*line.split(/=|;/)]
shell脚本报错:"[: =: unary operator expected"解决办法 在匹配字符串相等时,我用了类似这样的语句:
我已经想出了如何优先实现二元运算符,像这样(伪代码): method plus times() while(consume(plus_t)) do times() en
考虑这个管道。 let Pipeline = [ { $match: { }}, { $group: { workHours: { $sum: { $divid
我目前遇到一个问题,在你看它之前,请尝试认为我只是一个尝试使用带有函数的指针的初学者。 我解释一下自己:我需要有一个菜单( Function )可以调用任何其他函数,但我的问题是我从我的“main”调
我是一名优秀的程序员,十分优秀!