我发现了一个非常复杂的函数,这是一个快速平方根的实现.老实说,我不明白这个功能是如何工作的,但是a long和a 之间的以下转换float引起了我的注意:
i = *(long *) &y;
Run Code Online (Sandbox Code Playgroud)
我留下完整的代码
inline float Q_rsqrt(float number)
{
long i;
float x2, y;
const float threehalfs = 1.5F;
x2 = number * 0.5F;
y = number;
i = *(long *) &y;
i = 0x5f3759df - (i >> 1);
y = * (float *) &i;
y = y * (threehalfs - (x2 * y * y));
return y;
}
Run Code Online (Sandbox Code Playgroud) 我有一个小程序,在编译时会抛出以下错误
错误#2168:'+'的操作数具有不兼容类型'struct agenda'和'int'.
错误#2113:'.'的左操作数 具有不兼容的类型'int'.
错误#2088:需要左值.
这是我所做的代码
#include <stdio.h>
struct agenda{
int order, cellular;
char name[30], last_name[30], street[30], city[30], mail[50];
}contact[10];
int main(void)
{
struct agenda *ptrcontact;
ptrcontact = &contact[0];
(*ptrcontact+3).order = 3;
printf("\n\n %d", (*ptrcontact).order);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
因为它会抛出这些错误以及如何修复它们?