这是一个编译器错误!它已经被追溯到最终的输出汇编代码。我完全知道如何绕过这个bug,(我已经工作过了,谢谢)这个帖子的点就是知道bug。错误是没有产生任何输出代码,也没有警告编译器是不快乐的WI。这个代码实际上已经注释掉了所有的代码。“C”的值是不敬的,问题是编译器不产生代码,并且没有进行比较。至于==“int”,这不是真的。在定义中,它是最高的可变大小。在这种情况下,一个字节,它实际上是在汇编级上进行的测试,是一个单字节测试,(当输出代码被生成时)。就char而言,除非被编译器设置重写,否则需要将字符视为带符号字节。价值的定义。但是为了让每个人都高兴,我已经完全定义了它。至于“iT8*T”,它被定义为“符号char”,UIT88t被定义为“unChar char”。所以在这种情况下使用它绝对没有区别。{定义TestPoalValue\xFF'实际上是作为一个字符,当与char变量比较时,但是如果与一个未签名的字符比较,就会再次失败,并且不产生代码。这些是失败的条件,在所有情况下都需要编译器。生成输出代码(可能是相同的有效输出汇编代码)。一些编译器可能会发出的警告是:“比较签名和未签名的值”,我使用的每一个编译器都产生正确的结果,包括XC8,除了XC16失败。Q:什么是程序,我们在哪里报告编译器错误,以使它们修复?注意:绕过bug的方法是适当地施展常量,否则失败不会产生警告,也永远不会知道你有问题。当您发现代码不能按预期工作时,您的第一个提示将是。要找到问题,可能需要大量的工作通过代码进行跟踪才能找到丢失的输出程序集代码。
以上来自于百度翻译
以下为原文
This is a compiler bug! it has been tracked right back to the final output assembly code.
I know exactly how to get round this bug, (I had already worked that out, thanks)
The point of the post is make known the bug.
The bug is that no output code whatsoever is produced and there is no warning that the compiler is unhappy with the code and has in effect commented out the entire code out of existence.
The value of 'c' is irreverent, the problem is that compiler produces no code, and no comparison is done.
As far as the == promoting to an 'int' this is not true. by definition it casts to the highest variable size.
In this case a byte, which is in-fact the test done at the assembly level is a single byte test,( when output code is produced.)
As far as a char is concerned unless overridden by compiler settings, a char is required to be treated as a signed byte value by its very definition. But to keep everyone happy I have fully defined it.
As far as 'int8_t' it is defined as a "signed char" and uint8_t is defined as "unsigned char". so the use of this in this case makes absolutely no difference.
#define TEST_VALUE 'xFF'
does in-effect cast as a char and when comparing with a char variable works, but if compared with an unsigned char will again fail and produces no code.
These are the conditions that fail,
//case 1 - signed char
signed char c;
if(c == 0xFF) // no output code is produced. and no warnings
{
... // this includes all code between the { } missing
}
//case 2 - unsigned char
unsigned char c;
if(c == 'xFF') // no output code is produced. and no warnings
{
... // this includes all code between the { } missing
}
if(c == -1) // no output code is produced. and no warnings
{
... // this includes all code between the { } missing
}
In all cases the compiler is required! to produce output code ( which is likely to be the same effective output assembly code).
The warning that some compilers may/do issue is 'comparing signed and unsigned values'
Every other compiler i have used produces the right result including XC8, except XC16 which fails.
Q: What is the procedure and where do we report compiler bugs to, to get them fixed?
NOTE: The way around bug is to cast the constant as appropriate, failure to do so will produce no warnings and you will never know you have a problem. Your first hint will be when you find you code does not work as expected. To find the problem will likely take a lot of work tracing through your code only to find the output assembly code it is missing.