【发布时间】:2014-12-03 12:44:05
【问题描述】:
从另一个文件访问静态全局数组中的数据时出现分段错误;指针作为函数参数传递。两个文件显示的内存地址相同。
在文件 1.c 中
static long long T[12][16];
...
/* inside some function*/
printf(" %p \n", T); // Check the address
func_access_static(T);
...
在file2.c中
void func_access_static(long long** t)
{
printf(" %p \n", t); // shows the same address
printf(" %lld \n", t[0][0]); // gives segmentation fault
}
我是否正在尝试做一些无法做到的事情?任何建议表示赞赏。
【问题讨论】:
-
使用正确的函数签名。
long[][]和long**不同。 -
如何编译?
-
感谢大家的回复。 @RSahu 谢谢你的帖子。这很有帮助。
标签: c arrays static segmentation-fault arguments