Hello,
I have the following simple program
Code:
#include <stdio.h>
#include <math.h>
#define maxG 500
typedef struct _test {
float c[maxG][maxG][maxG];
int gX, gY, gZ;
} test;
int main() {
int i, j, k;
test p1, p2;
p1.gX = 5;
p1.gY = 3;
p1.gZ = 6;
p2.gX = 2;
p2.gY = 6;
p2.gZ = 3;
return 0;
}
which compiles, but gives a segmentation fault on execution.
I'm on Linux, I compiled using gcc or gcc-4.4, and used gdb to debug and obtained the following
Code:
Program received signal SIGSEGV, Segmentation fault.
main () at main.c:17
17 p2.gX = 2;
(gdb) print p1
Não é possível acessar a memória no endereço 0x7fffffffe228
(gdb) print &p1
$1 = (test *) 0x7fffffffe228
(gdb) print &p2
$2 = (test *) 0x7fffffffe228
(gdb) print &p1.c
$3 = (float (*)[500][500][500]) 0x7fffffffe228
(gdb) print &p2.c
$4 = (float (*)[500][500][500]) 0x7fffffffe228
Now, am I seeing this wrong, or p1 and p2 are occupying the same space? Anyone can give a hint on what I did wrong?
Thanks a lot,
Abel