D
Dieter
Hi.
In the snippet of code below, I'm trying to understand why when the
struct dirent ** namelist
is declared with "file" scope, I don't have a problem freeing the
allocated memory. But when the struct is declared in main (block scope)
it will segfault when passing namelist to freeFileNames().
Since this seems to be just a matter of my understanding scope and
pointer parameter passing better, I only included what thought to be
relevant code. I'll happily provide compilable code if deemed necessary.
Please see commented lines:
struct dirent **namelist; /* file scope works */
int main(void)
{
/* struct dirent **namelist */ /* block scope doesn't work */
int n;
n = getFileNames(H5DIR, namelist); /* included from mylib.h */
freeFileNames(namelist, n); /* included from mylib.h */
return 0;
}
Thank you very much for your comments,
Dieter
In the snippet of code below, I'm trying to understand why when the
struct dirent ** namelist
is declared with "file" scope, I don't have a problem freeing the
allocated memory. But when the struct is declared in main (block scope)
it will segfault when passing namelist to freeFileNames().
Since this seems to be just a matter of my understanding scope and
pointer parameter passing better, I only included what thought to be
relevant code. I'll happily provide compilable code if deemed necessary.
Please see commented lines:
struct dirent **namelist; /* file scope works */
int main(void)
{
/* struct dirent **namelist */ /* block scope doesn't work */
int n;
n = getFileNames(H5DIR, namelist); /* included from mylib.h */
freeFileNames(namelist, n); /* included from mylib.h */
return 0;
}
Thank you very much for your comments,
Dieter