gpt4 book ai didi

objective-c - C语言。逻辑错误 : The left operand of '-' is a garbage value

转载 作者:搜寻专家 更新时间:2023-10-30 20:25:55 25 4
gpt4 key购买 nike

我有以下代码,但在这行代码中我有警告 x[i] = (rhs[i] - x[i - 1])/b;,编译器告诉我认为 rhs[i] 是垃圾值。为什么会这样?以及如何删除此警告?

double* getFirstControlPoints(double* rhs, const int n) {
double *x;
x = (double*)malloc(n * sizeof(double));
double *tmp; // Temp workspace.
tmp = (double*)malloc(n * sizeof(double));

double b = 2.0;
x[0] = rhs[0] / b;
for (int i = 1; i < n; i++) // Decomposition and forward substitution.
{
tmp[i] = 1 / b;
b = (i < n - 1 ? 4.0 : 3.5) - tmp[i];
x[i] = (rhs[i] - x[i - 1]) / b; //The left operand of '-' is a garbage value
}
for (int i = 1; i < n; i++) {
x[n - i - 1] -= tmp[n - i] * x[n - i]; // Backsubstitution.
}
free(tmp);
return x;
}

enter image description here

enter image description here

您可能会在屏幕截图上看到所有编译器警告和调用 getFirstControlPoints

最佳答案

您需要检查以确保您在 points 中至少有 4 分数组,因为这个循环(第 333 行):

for (NSInteger i = 1 ; i < n - 1 ; ++i) {
// initialisation stuff
}

对于 n = 0, 1, 2 根本不会执行。

假设points其中有 3 个对象,在第 311 行,您将 n 设置为计数 - 1 即 n == 2

那么循环条件就是i < 2 - 1i < 1 .

我认为你需要循环条件为 i < n

关于objective-c - C语言。逻辑错误 : The left operand of '-' is a garbage value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12073315/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com