I'm trying to build somebody else's C program on my Mac, using command line tools to build a command line program. Straightforward C program, should be as simple as anything. But I'm getting really strange memory access errors during declaration and initialization of variables in main(), so early that I really don't see how I could have messed anything up. This is basic core C language material, how it could be failing really beats me.
Ken$ gcc -std=c99 -ggdb srtm2stl.c geometry.c stlwriter.c -o srtm2stl
Ken$ gdb ./srtm2stl
. . .
(gdb) run
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x00007fff5b74f6c0
0x0000000100000e37 in main (argc=10, argv=0x7fff5fbff990) at srtm2stl.c:195
195 char SolidName[132] = {' '}; // Optional name for solid (text format STL files)
(gdb) list 195
190 int main(int argc, char *argv[])
191 {
192 FILE *in = NULL; // input file
193 FILE *out = NULL; // output file
194
195 char SolidName[132] = {' '}; // Optional name for solid (text format STL files)
196 // char SolidName[132]; // Optional name for solid (text format STL files)
197 int Verbose = 0; // Flag: Verbose
The only thing that comes to mind is that it's building in 64-bit mode, and I've never built a 64 bit program before. Are there other command line arguments that need to be given to gcc to make this work properly? Or other theories?
Note line 196. If I comment out line 195 and use 196 instead, we get a little farther before a similar crash:
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x00007fff5b74f8e0
main (argc=1, argv=0x7fff5fbffa20) at srtm2stl.c:216
216 unsigned int i = 0;
(gdb) list 216
214 long Bias = 0;
215 short grid[MAXROWS][MAXCOLS]; // Array to hold the elevations
216 unsigned int i = 0;
217 short stemp;
Seems like there's something about arrays. MAXROWS and MAXCOLS are each 6001 in this build, that shouldn't be overwhelming with modern memory sizes. Right?
OSX 10.7.5, gcc version i686-apple-darwin10-llvm-gcc-4.2, GNU gdb 6.3.50-20050815