c - Accessing static global array from another file via function argument -
getting segmentation fault while accessing info static global array file; pointer passed function argument. memory address shows same both file.
in file1.c
static long long t[12][16]; ... /* within function*/ printf(" %p \n", t); // check address func_access_static(t); ...
in file2.c
void func_access_static(long long** t) { printf(" %p \n", t); // shows same address printf(" %lld \n", t[0][0]); // gives segmentation fault }
am trying can't done? suggestion appreciated.
**
not same thing array.
declare function
void func_access_static(long long t[][16])
or
void func_access_static(long long (*t)[16])
this 2 dimensional array int t[2][3]
looks in memory
t t[0] t[1] +---------+---------+---------+---------+---------+---------+ | t[0][0] | t[0][1] | t[0][2] | t[1][0] | t[1][1] | t[1][2] | +---------+---------+---------+---------+---------+---------+ contiguous memory cells of int type
this pointer on pointer int **
looks in memory
pointer pointer pointer +---------+ +---------+---------+ | p | --> | p[0] | p[1] | +---------+ +---------+---------+ | | somewhere in memory | | +---------+---------+---------+ | \---------->| p[1][0] | p[1][1] | p[1][2] | | +---------+---------+---------+ | | somewhere else in memory | +---------+---------+---------+ \-------------------->| p[0][0] | p[0][1] | p[0][2] | +---------+---------+---------+
to access content it's same syntax operation quite different.
c arrays static segmentation-fault arguments
No comments:
Post a Comment