linux两个数交换为什么有警告,多谢解答
linux两个数交换为什么有警告,谢谢解答
void swap(int *a,int *b){
int c;
c=*a;
*a=*b;
*b=c;
}
运行程序后显示:practice.c:74: warning: passing argument 1 of ‘swap’ makes pointer from integer without a cast
------解决方案--------------------
编译器提示传给swap()的第一个参数类型不匹配。
可以贴出调用swap()的代码。
------解决方案--------------------
------解决方案--------------------
还是没有取地址操作阿!
------解决方案--------------------
==》
void swap(int *a,int *b){
int c;
c=*a;
*a=*b;
*b=c;
}
运行程序后显示:practice.c:74: warning: passing argument 1 of ‘swap’ makes pointer from integer without a cast
------解决方案--------------------
编译器提示传给swap()的第一个参数类型不匹配。
可以贴出调用swap()的代码。
------解决方案--------------------
#include <stdio.h>
#define SWAP(a,b) do ((&(a))!=(&(b)))?((a)^=(b)^=(a)^=(b)):((a)=(a)); while (0)
char *p1="1" ,*p2="2" ;
char c1=1 , c2=2 ;
short s1=1 , s2=2 ;
int i1=1 , i2=2 ;
__int64 I1=1i64, I2=2i64;
float f1=1.0f, f2=2.0f;
double d1=1.0 , d2=2.0 ;
void main() {
SWAP((int)p1,(int)p2); printf("char * %5s, %5s\n",p1,p2);
SWAP(c1,c2); printf("char %5d, %5d\n",c1,c2);
SWAP(s1,s2); printf("short %5d, %5d\n",s1,s2);
SWAP(i1,i2); printf("int %5d, %5d\n",i1,i2);
SWAP(I1,I2); printf("__int64 %5I64d,%5I64d\n",I1,I2);
SWAP(*(int *)&f1,*(int *)&f2);printf("float %5g, %5g\n",f1,f2);
SWAP(*(__int64 *)&d1,*(__int64 *)&d2);printf("double %5lg, %5lg\n",d1,d2);
SWAP(c1,c1);
printf("%d\n",c1);
}
//char * 2, 1
//char 2, 1
//short 2, 1
//int 2, 1
//__int64 2, 1
//float 2, 1
//double 2, 1
//2
------解决方案--------------------
还是没有取地址操作阿!
------解决方案--------------------
swap(buf[k],buf[j]);
==》
swap(&buf[k], &buf[j]);