C++中奇怪的功能输入
Strange input of function in C++
(1L<<16u)
在以下代码中做了什么?以及此pointer(&mode_absolute_pos_el.tracking)
作为函数输入的作用是什么?
if (command_axis2.cif_mode_state == STATUS__DONE)
{
delta_position = absolute_position - turret_pos.elevation_16bit_pm180deg;
delta_position = MathRange_PlusMinusHalfRange32Bit(delta_position, 1L<<16u);
mode_absolute_pos_el.speed_setpoint = MathTracking_Main(&mode_absolute_pos_el.tracking, delta_position, 0L);
}
这是完整函数所要求的完整函数:
static int16_t TwinX_AbsPos_Calc_El(int16_t absolute_position)
{
uint16_t position_reached = NO;
int32_t delta_position = 0L;
if (command_axis2.cif_mode_state == STATUS__DONE)
{
delta_position = absolute_position - turret_pos.elevation_16bit_pm180deg;
delta_position = MathRange_PlusMinusHalfRange32Bit(delta_position, 1L<<16u);
mode_absolute_pos_el.speed_setpoint = MathTracking_Main(&mode_absolute_pos_el.tracking, delta_position, 0L);
/* verify that absolute position is reached with tolerance: +/- CUSTOMER_ABSOLUTE_POS_ERROR
* for more than MODE_ABSOLUTE_POS_OK_DELAY_IN_MS:
* bai: That has to be here because otherwise position_reached is always "Yes" because delta_position == 0L */
if ((delta_position < TwinX_MODE_ABSOLUTE_POS_ERROR) && (delta_position > (-1 * TwinX_MODE_ABSOLUTE_POS_ERROR)))
{
position_reached = YES;
}
mode_absolute_pos_el.absolute_pos_reached = MathDebounce_Status(&mode_absolute_pos_el.debounce, position_reached);
}
else
{
mode_absolute_pos_el.speed_setpoint = 0;
MathTracking_SetStartCondition(&mode_absolute_pos_el.tracking, turret_speed.elev_speed_max16bit);
}
return mode_absolute_pos_el.speed_setpoint;
}
下面你可以看到MATH_DEBOUNCE:
typedef struct
{
bool_t debounced_status; /* debounced status ZERO / ONE */
uint32_t debounce_counter; /* counter */
uint32_t threshold_for_zero; /* threshold to set debounced status to ZERO */
uint32_t threshold_for_one; /* threshold to set debounced status to ONE */
uint32_t step_down_size; /* step size to count down. used for underclock */
}MATH_DEBOUNCE_t;
void MathDebounce_Init(MATH_DEBOUNCE_t *const debounce_p,
bool_t initial_status,
uint16_t debounce_delay,
uint16_t underclock);
void MathDebounce_ResetStatus(MATH_DEBOUNCE_t *const debounce_p, bool_t reset_status);
bool_t MathDebounce_Status(MATH_DEBOUNCE_t *const debounce_p, bool_t status);
1 << 16
是 2^16。 <<是一个左二进制移位运算符。
让我们看看如何得到 2^3,想象一下你有 1,它以二进制形式看起来像这样0b0001
。关于二进制系统的一点是,2 的幂在其二进制表示中只有一个位,所以2^3 = 8
看起来像0b1000
。这是获得 2 次方的非常快速的方法。
将指针传递给函数通常是从中获取多个输出的一种方法。就像当返回值类似于错误代码时,函数的实际输出是通过您传递给它的指针传递的。
但是很难说它到底做了什么,因为你没有提供函数的代码。
相关文章:
- LLVM | codegen 用于带有命令行选项的程序输入功能
- 基本 在C++生成器中输入关键功能
- 而大写和小写字母输入功能
- C++:功能在输出前自动使用50减/增加输入数
- 通过功能进行2D矢量输入和显示
- 具有用户输入C++的功能循环
- 如何在控制台应用程序中添加滚动功能以显示更大的输入
- 扫描线C++不接受输入的功能
- Vigenere密码的C++功能有时才起作用(适用于某些输入,跳过其他输入的班次)
- 此功能希望从std :: istream解析该功能的输入格式
- 通用功能模板返回一个大小的容器比输入容器的大小小
- 功能调用不起作用,但控制台仍允许输入
- 当程序输入主要功能时,为什么要清除此std ::向量
- C 将用户输入从一个函数到另一个功能,并使用Main(Newbie)显示
- CIN 在首次使用功能后不允许输入
- 支架检查功能仅测试输入的前 2 个
- 如何在获取用户输入时运行相同的功能
- 我如何将输入分配给在 for 循环中设置的映射功能
- C++中奇怪的功能输入
- 发送密钥功能输入密钥问题