错误:没有链接的'y2'的重新声明
问题描述:
我正在创建一个程序,该程序接收整数值并使用atoi将它们转换为2的补码整数,并确定进行了哪种类型的转弯。这里是我的代码:错误:没有链接的'y2'的重新声明
#include <stdio.h>
#include <stdlib.h>
int turn(int turn, int a1, int b1, int a2, int b2, int a3, int b3){
;
turn = ((a1 * b1 + b1 * a3 + a2 * a3) - (b2 * a3 + a1 * b3 + a2 * b1));
printf("\n value = %d \n", turn);
return(turn);
}
int main(int argc, char *argv[]) {
int x1, y2, x2, y2, x3, y3, turn;
x1 = atoi(argv[1]);
y1 = atoi(argv[2]);
x2 = atoi(argv[3]);
y2 = atoi(argv[4]);
x3 = atoi(argv[5]);
y3 = atoi(argv[6]);
turn = turn(x1, y1, x2, y2, x3, y3);
if(turn == 0) printf("\n Straight \n");
if(turn < 0) printf("\n Right Turn \n");
if(turn > 0) printf("\n Left Turn \n");
return 0 ;
}
而且我的错误:
make -k p3
cc p3.c -o p3
p3.c: In function ‘main’:
p3.c:29:19: error: redeclaration of ‘y2’ with no linkage
p3.c:29:11: note: previous declaration of ‘y2’ was here
p3.c:32:3: error: ‘y1’ undeclared (first use in this function)
p3.c:32:3: note: each undeclared identifier is reported only once for each function it appears in
p3.c:38:14: error: called object ‘turn’ is not a function
make: *** [p3] Error 1
编译的代码2日太阳异常退出9月22日20时07分02" 秒
我想知道这种情况的原因错误。
感谢,
答
的错误,你得到是完全的信息是什么 告诉你。
- 你声明你的变量
y2
两次 - 你没有申报任何地方
y1
- 你不能有这样两个名称相同的成员。您有一个
turn
变量,它与turn
函数具有相同的名称。
+0
谢谢..错误地声明y2两次,而不是y2和y1。 – user190494
答
在INT打开声明的main()()之前;你有这样的事情int Turn(){; 应该是{或;}。
在Main()中,您声明了Y2两次,其中一个应该是Y1。
注意:{开启后不能;在你的代码中有它
对于函数名和参数名都使用“turn”是最好的。使用这个参数作为局部变量更不健康。你强迫调用者转()来证明第一个参数不被用来传递或返回一个值,这样你就不必在返回之前声明一个局部变量来保存结果。我建议你从参数列表中“转出”,然后声明一个局部变量,最好使用不同的名称。 –
转弯功能编译很奇怪。转可能是一个函数指针,并导致分配给左值的问题。外转也造成主 –