The error in the following code is that memcpy(t[j], m[j], sizeof(int) * DIM * DIM);
should be memcpy(t[j], m[j], sizeof(int) * DIM);
:
// Untitled7.c
#include <stdio.h>
#include <string.h>
#define DIM 1000
int main(void)
{
int m[DIM][DIM], t[DIM][DIM];
unsigned j, k;
for(j = 0; j < DIM; j++)
for(k = 0; k < DIM; k++)
m[j][k] = j * DIM + k;
for(j = 0; j < DIM; j++)
memcpy(t[j] ,m[j], sizeof(int) * DIM * DIM); // only one DIM
for(j = 0; j < DIM; j++)
for(k = 0; k < DIM; k++)
m[j][k] = t[DIM-k-1][j];
return 0;
}
Using gdb how could I find that error? I understood how to create the core file (using ulimit -c unlimited
), then I used $ gdb Untitled7 core
and it gives:
...
Reading symbols from Untitled7...done.
[New LWP 10610]
Core was generated by ` ? @ A'. // and symbols of binary files
Program terminated with signal SIGSEGV, Segmentation fault.
#0 __memcpy_ssse3 () at ../sysdeps/i386/i686/multiarch/memcpy-ssse3.S:2590
2590 ../sysdeps/i386/i686/multiarch/memcpy-ssse3.S: File o directory non esistente. // File or directory not existent.
After what should I do?