[英]Read value from function returning pointer
I am developing a code in which I need to read the value of function which returns value in pointer. 我正在开发一个代码,在其中我需要读取在指针中返回值的函数的值。
below is the function whose value needs to be read (*ip) 以下是需要读取其值的函数(* ip)
int16_t getLastValueFromADC()
{
volatile uint16_t *ip;
ip = GET_FPGA_REGISTER_ADDRESS(REG_CURRENT_ADC_SAMPLE_R);
#ifdef _JSB_BEHAVIOUR_0_65536
if (tighteningDirectionCCW)
{
tempValue = (int16_t)(*ip);
tempValue = (OFFSET_BB2AD - tempValue);
}
else
{
tempValue = ((*ip) + OFFSET_BB2AD);
}
return ((uint16_t)tempValue);
#endif
return *ip;
}
I am reading the value using below code: 我正在使用以下代码读取值:
int16_t vref2v5 = getLastValueFromADC();
printf("VREF2V5 Status for Torque signal: %d\n",vref2v5);
not getting expected values it is showing some negative value number. 没有得到期望值,它显示了一些负值。
Please suggest 请建议
Thanks & Regards 感谢和问候
The return type of the function is a 16 bit integer, 该函数的返回类型是16位整数,
int16_t getLastValueFromADC();
However the variable used to represent the result to be returned by the function is an unsigned integer. 但是,用于表示函数要返回的结果的变量是无符号整数。
volatile uint16_t *ip;
Unsigned integers are meant to be parsed by the compiler in such a way that there value is always positive. 无符号整数应由编译器以这种方式进行解析,使得值始终为正。 This is not the case with regular(signed) integers, in which case the MSB(most significant bit; leftmost bit) determines whether the value should be treated as postive(0) or negative(1). 对于正则(带符号)整数则不是这种情况,在这种情况下,MSB(最高有效位;最左侧的位)确定该值应视为正值(0)还是负值(1)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.