子函数返回值数组赋值给指针,调试监控指针显示无法读取内存
定义的全局变量
unsigned long long ll_a[5] = { 1844674409709551615,1844674409709551615,1844674409709551615,1844674409709551615 ,0 };
unsigned long long ll_b[5] = { 1844674409709551615,115292150606846975,115292150606846975,115292150606846970 ,0 };
long long ll_p[5] = { 4294967293 ,4294967293 ,4294967293 ,4294967293 ,0 };
long long ll_k[5] = { 4294967293 ,4294967293 ,4294967293 ,4294967293 ,0 };
long long* p;
unsigned short us_datalength = 4;
unsigned short us_bitlenght = 64;
unsigned short us_carrybit = 0;
unsigned long long* l;
unsigned long long ll_z[5] = {0};
main.c文件
int main()
{
unsigned short i;
l= sub(ll_a, ll_b);
for (i = 0; i < 5; i++)
{
printf("a[]= %llu\n", *(l+i));
}
return 0;
}
子函数sub在sub.c文件
unsigned long long sub(unsigned long long a[], unsigned long long b[])
{
unsigned short i;
static unsigned long long ll_z[5];
us_carrybit = 0;
for (i = 0; i < us_datalength; i++)
{
if (a[i] < (b[i] + us_carrybit))
{
ll_z[i] = (unsigned long long) ((0x01 << us_bitlenght) - 1) + a[i] - b[i] - us_carrybit;
us_carrybit = 1;
}
else
{
ll_z[i] = a[i] - b[i] - us_carrybit;
us_carrybit = 0;
}
} ;
return ll_z;
}
运行结果及报错内容
调试时在printf会报如下异常。监控指针l会显示无法读取内存
0x00007FF68E6118BE 处(位于 ECC Project.exe 中)引发的异常: 0xC0000005: 读取位置 0xFFFFFFFF8E61C248 时发生访问冲突。
我的解答思路和尝试过的方法
同样的main函数,我放到sub.c文件执行,就完全没有问题。
我上面的程序是否存在指针越界?所以才出现这个问题?
我想要达到的结果
请问,如果我的主函数和子函数是两个.c文件,为什么 报错,怎么解决呀?