expected 'float **' but argument is of type 'float (*)[5]'
来源:互联网 发布:虚拟机centos安装教程 编辑:程序博客网 时间:2024/06/02 06:02
出错代码:
#include<stdio.h>#include<string.h>#define NUM_NODE 5int test(float **array,int len){ array[0][2]=123.45; return 0;}int main(){ float num[NUM_NODE][NUM_NODE]; memset(num,0,NUM_NODE*NUM_NODE*sizeof(float)); test(num,NUM_NODE); return 0;}
编译提示:expected 'float **' but argument is of type 'float (*)[5]'。
而且传递后的二维指针,如果有赋值操作,则会导致程序崩溃。
但是,将test函数转换为int test(float (*array)[NUM_NODE],int len),警告消失。这充分说明二维数组,同二维指针其实是不一样的。二维数组的类型为float(*)[NUM_NODE]。
而且二维指针的分配内存和二维数组也是不同的,内存分布不同;
int test(float **array,int len){ array[0][2]=123.45; return 0;}int main(){ float **num=NULL; int i=0; for(i=0;i<NUM_NODE;i++) { num=(float **)malloc(NUM_NODE*sizeof(float*)); } for(i=0;i<NUM_NODE;i++) { num[i]=(float*)malloc(NUM_NODE*sizeof(float)); } printf("%p,%p\n",num,&num); float **ptr=num; ptr[0][1]=123.45; test(num,NUM_NODE); return 0;}
记录在此。我觉的这个问题要是研究明白,需要理解编译原理。
阅读全文
0 0
- expected 'float **' but argument is of type 'float (*)[5]'
- DPDK中文-编译出错 expected __m128i but argument is type int
- Bean named 'BService' is expected to be of type 'path1' but was actually of type 'path2'
- is expected to be of type but was actually of type 'com.sun.proxy.$Proxy70'
- fast sqrt of type float
- No unique bean of type is defined: expected single bean but found 0
- No qualifying bean of type is defined: expected single matching bean but found 2
- is expected to be of type 'org.com.ssh.hibernate.AOPService.EchoTest' but was actually of type 'com.
- Nil is not compatible with expected argument type '[String : AnyObject]'
- call of overloaded 'round(&float)' is ambiguous
- jni编译时出现:warning: format '%d' expects argument of type 'int', but argument 4 has
- cannot convert value of type 'String!' to expected argument type 'inout String'
- Cannot convert value of type 'SecTrustResultType' to expected argument type 'UInt32'
- Sybase Precision for the Float type of table's column
- [C/C++]warning: format '%c' expects argument of type 'char*', but argument 2 has type 'int' [-Wforma
- inet_ntoa编译提示警告: 格式 ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Wformat]
- g++编译报错原因分析 format ?.d?.expects argument of type ?.nt?. but argument 3 has type ?.
- linux c之提示format‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long int’ [-Wformat
- 多线程与高并发
- 大整数减法
- java泛型<一>
- AJAX学习(二)AJAX的三种交互格式
- #bzoj3380#小Q的新玩具(DP + set优化 / 线段树优化)
- expected 'float **' but argument is of type 'float (*)[5]'
- 指针,久违了!
- 二叉树的遍历
- 数据库连接池
- Java serialversionuid 生成流程
- HDU 3699 A hard Aoshu Problem
- JS程序设计基础总结
- Lua5.1 源码注释(一) table.c
- linux驱动和应用程序如何上传到路由器