c++ - 警告 : format ‘%5f’ expects type ‘double’ , 但参数 3 的类型为 ‘int’

标签 c++ opengl floating-point compiler-errors printf

我(仅)收到以下编译错误:

RuberSystem.cpp:425: warning: format ‘%5f’ expects type ‘double’, but argument 3 has type ‘int’

以下是声明:

float x = 6000.0f;
float z = -6000.0f;
float lx = -6000.0f;
float lz = 6000.0f;
float angle = 0.0f;

这是第 425 行:

printf("Right pressed: angle=%5f\nx=%5f\nlx=%5f\nz=%5f\nlz=%5f",angle,x,lx,z,lz);

这些变量经历的唯一操作是:

angle -= 0.01f;
lx = sin (angle);
lz = -cos (angle);

我也尝试使用 (float) 来转换这些操作,但没有成功。

可能有用的信息:这在我的 Windows 计算机上的 Visual Studio 8 中运行,现在我正在我的 MacBook 上使用 GNU g++ 进行编译。我已经为 mac 使用设置了正确的定义。

编辑:我发现对这些变量还有一项操作:

gluLookAt(
  x, 1500.0, z,    // eye location
  x+lx, 0.0,   z+lz,    // center location
  0.0, 1.0,   0.0); //open GL function

我查看了 gluLookAt 的代码,它似乎接受 float 并将它们存储在 float 矩阵中,所以我也没有看到问题存在,但我认为这将是一件好事分享。

答案:我是个白痴。正在调用 angle -= 0.01f;... 的方法有名为 int x 的参数和int y ,因此void processSpecialKeys(int key, int x, int y) { .

最佳答案

第 425 行是否有不同的 x 声明?例如:

float x;
void func(int x) { ... }

// or

float x;

for (int x = ...)
{
}

// or

#define x ...

关于c++ - 警告 : format ‘%5f’ expects type ‘double’ , 但参数 3 的类型为 ‘int’,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13596642/

相关文章:

c++ - 对象数组的默认复制行为

c++ - OpenGL程序画三角形给出蓝屏

c++ - 无法渲染 Quake 3 map

java - 为什么像获取和添加这样的原子操作会返回被更改变量的旧值?

c++ - 纹理不会在 OpenGL 和 Xcode 上显示

c++ - C++ 中 placement new 执行的完整操作列表是什么?

opengl - 片段着色器 - 画一条线?

c++ - 什么时候在映射/排序中使用标准 < 比较 double 是安全的?

c++ - 将 QString 转换为 float 给我错误

c++ - 我有一个浮点溢出问题