Also sprach Godfree:
> Please help
> I'm having problems when I'm using the sizeof() function in 
> combination with the multiplication operator, eg.
> sizeof(dir_ent) * (*count)
> where dir_ent is a structure and *count is a pointer to an integer. 
> During compilation no errors are reported but as soon as I run the 
> program, a segmentation fault is reported.

My guess is that `count' refers to uninitialized memory.  The test program
below compiles and runs without incident, even when compiling Electric
Fence and setting EF_ALIGNMENT=0.

#include <stdio.h>
#include <dirent.h>

int main(void)
{
        int *count;
        struct dirent dir_ent;
        *count = 1;

        fprintf(stdout, "sizeof(dir_ent) * (*count) = %d\n", 
                sizeof(dir_ent) * (*count));

        return 0;
}
-- 
algorithm, n.:
        Trendy dance for hip programmers.

Reply via email to