作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我有以下代码,但在这行代码中我有警告 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;
}
您可能会在屏幕截图上看到所有编译器警告和调用 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 - 1
即 i < 1
.
我认为你需要循环条件为 i < n
关于objective-c - C语言。逻辑错误 : The left operand of '-' is a garbage value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12073315/
我是一名优秀的程序员,十分优秀!