- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这本书讲述了这样的写作:
static unsigned int foo;
以后
if( foo > 0)
{
是错误的,它会导致一个很难发现的错误。这是为什么?
在 x86 汇编语言编程中,有带符号的算术指令和还有无符号算术指令,JG JL <-符号算术JB JA <- 未签名指令。
所以编译器可以用无符号指令组装 if (foo >0 ) 语句不是吗?有人可以提前解释一下它是如何工作的吗?
这个指令错了吗?或者如果“C”中的“C++”是严格的那个案子?请解释。
这里我们比较一个无符号变量和一个立即数。里面发生了什么在这种情况下实际上是编译器?
当我们比较有符号值和无符号值时会发生什么?那么编译器会选择什么指令,有符号指令还是无符号指令?
--提前致谢--
最佳答案
这个问题不应该在汇编程序级别上回答,而应该在 c/c++ 语言级别上回答。在大多数体系结构上,不可能比较有符号数和无符号数,并且 c/c++ 不支持此类比较。相反,有关于将一个操作数转换为另一个操作数的类型以便比较它们的规则 - 例如参见 this question 的答案
关于与文字进行比较 - 典型的做法(就像你所做的那样)并没有错,但你可以做得更好 - 根据 c++ 标准:
2.13.1.1 An integer literal is a sequence of digits that has no periodor exponent part. An integer literal may have a prefix that specifiesits base and a suffix that specifies its type. The lexically firstdigit of the sequence of digits is the most significant. A decimalinteger literal (base ten) begins with a digit other than 0 and con-sists of a sequence of decimal digits. An octal integer literal (baseeight) begins with the digit 0 and con- sists of a sequence of octaldigits.22) A hexadecimal integer literal (base sixteen) begins with 0xor 0X and consists of a sequence of hexadecimal digits, which includethe decimal digits and the letters a through f and A through F withdecimal values ten through fifteen. [Example: the number twelve can bewritten 12, 014, or 0XC. ]
2.13.1.2 The type of an integer literal depends on its form, value,and suffix. If it is decimal and has no suffix, it has the first ofthese types in which its value can be represented: int, long int; ifthe value cannot be repre- sented as a long int, the behavior isundefined. If it is octal or hexadecimal and has no suffix, it has the first of these types in which its value can be represented: int,unsigned int, long int, unsigned long int. If it is suffixed by u orU, its type is the first of these types in which its value can berepre- sented: unsigned int, unsigned long int. If it is suffixed by lor L, its type is the first of these types in which its value can berepresented: long int, unsigned long int. If it is suffixed by ul, lu,uL, Lu, Ul, lU, UL, or LU, its type is unsigned long int.
如果您想确定您的字面类型(以及同类型),请添加描述的后缀以确保字面类型正确。
还值得注意的是,字面量 0
实际上不是十进制而是八进制 - 它似乎没有改变任何东西,但却出乎意料 - 或者我错了吗?
总结一下——这样写代码并没有错,但你应该记住,在某些情况下,它的行为可能违反直觉(或者至少是反数学的;)
关于c++ - Static unsigned int foo 和后来的 if ( foo >0 )?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7439268/
public class Foo : IFoo ... 和有什么区别 IFoo foo = new Foo(); 和 Foo foo = new Foo(); 最佳答案 区别仅在于变量的声明类型。每当
class Foo { public: explicit Foo() {} explicit Foo(Foo&) {} }; Foo d = Foo(); error: no matc
是 foo as? Foo完全等同于 foo as Foo? ? 如果是,那为什么两者都有? 如果不是,那么有什么区别? 最佳答案 as?是 safe cast operator . 通常,如果您尝试
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 9 年前。 Improve
这个问题在这里已经有了答案: Why is there an injected class name? (1 个回答) 关闭5年前。 一位同事不小心写了这样的代码: struct foo { fo
我遇到了这些关键字::foo、::foo、::bar/foo 和 :bar/foo 您能举例说明差异吗? 最佳答案 :foo 是一个非完全限定的关键字。它没有关联的命名空间。 (name :foo)
有人问我如何简化这个 lambda (Foo foo) -> foo.getName() 还有更好的写法吗? 最佳答案 Foo::getName。 假设getName是一个实例方法,其签名中的参数列表
编写此规则集的 CSS 组合器或简写是什么? foo bar, foo biz, foo gaz > boo, foo tar { ... } 我很确定我在 MDN 的某处读到过有一个。是不是: f
我有一个用这个字符串填充的输入文本 "foo foo"但插入后字符串看起来像这样 "foo foo" .我该如何解决?我想以第一种格式显示字符串! 最佳答案 你可能有这样的事情: " /> 更改 va
假设我有一个不可复制类Foo,它的构造函数之一恰好接收到对 Foo 的引用。 class Foo { public: Foo(Foo& parent) {...} private: v
class Artist @@song_count = [] attr_accessor :name, :songs def initialize(name) @name = name
请解释为什么这些 Perl 函数的调用方式在函数定义之上决定了它们是否运行。 print "Why does this bare call to foo not run?\n"; foo; print
文件名分为三种类型 首先( Root 于某种“当前工作目录”之下) ../foo ./foo bar/foo # really in this group? 和( Root 于绝对路径,独立于 CWD
我想自动连接 foo: @Autowired Foo foo 但我无法修改类 Foo 并将其标记为 @Component。 Autowiring foo 最干净的方法是什么? 顺便说一句,如果您需要使
我一直在使用 Python 的 ElementTree 创建 XML 文档,到目前为止一切顺利。然而我现在面临的问题是,由于项目要求,我需要生成一个 XML 文档,其中包含带有开始和结束标签的元素以及
class Foo { public: Foo(){} private: Foo(const Foo &); }; Foo f(); Foo f1 = Foo(); 我发现当我将 Fo
我有一个 jquery 对话框,上面有一个按钮(我的按钮,不是对话框按钮之一)。 设置对话框后,我有以下代码: $('#bar').click(foo('baz')); 当我加载页面并显示对话框时,f
我遇到了以下变量的情况: var foo: Foo | Foo | Foo; 动态生成(使用 keyof 和 stuff),这在代码的那个点是完全有意的。但是,我需要调用像这样定义的对象内部的方法:
clang 3.5.0 和 gcc 4.9.1 从代码生成的可执行文件 #include struct Foo { Foo() { std::cout << "Foo()" << std::e
对于声明为 Foo& foo = ...; 的 foo,lambdas 的按值捕获和按引用捕获语义之间有什么区别吗? 最佳答案 我认为你已经陷入了一个常见的误解......引用是对真实对象的别名。初始
我是一名优秀的程序员,十分优秀!