This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] TMS320F28388D:如何比较两个有符号数?

Guru**** 2542340 points


请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1281247/tms320f28388d-how-to-compare-two-signed-numbers

器件型号:TMS320F28388D

下午好。

请告诉我如何比较 C 语言中的两个有符号数?

int32_t res;
int32_t mass_U300[16];
int32_t norm_u300v = 0x7F68;

uint8_t detection_v (void) {

for (i = column_1; i <= column_4; ++i) {
    res = mass_U300[i];

			if ( res >  norm_u300v ) {
				erro_u300v = 0x2; //above normal
			} else if (res < ((int32_t)0x303A) ) {
				erro_u300v = 0x1; //below normal
			
			} else{
			    erro_u300u = 0;
			}
}
			
	return erro_u300v;
}

Mass_U300的值根据程序的执行而变化。

为什么该函数始终返回 erro_u300v = 0x2?
第一个条件始终满足。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Sergey:

    您能否在 CCS 中单步执行您的代码而不进行任何优化、并在运行时向我显示这两个变量的表达式视图? 我想查看它们正在比较什么值(您应该能够正常地比较有符号整数、这应该不会有问题)。

    此致、

    阿米尔·奥马尔