I'm writing an ANSI C program and have a bug somewhere I'm unable to find. I'm new to C so don't discount the obvious.
I have three files in use. The first is a header file I include in the other 2 files using #include "myheader.h". Inside this header file I have, among other things, a function prototype of:
double function1(double *, double *, double *, int *, int, int);
The second file contains the main() function. This includes, among other things, the declaration of variable APRON as:
int APRON[8] = {1, 2, 3, 4, 5, 6, 7, 8};
Using gdb in this file I observe:
(gdb) p APRON
$1 = {1, 2, 3, 4, 5, 6, 7, 8}
Then this array is passed to another file (file3) as an argument in the following function call:
zz = function1(aa, bb, cc, APRON, dd, ee);
In file3, the function is defined as:
double function1(double *aa, double *bb, double *cc, int *bins, int dd, int ee)
When gdb enters this file3, I immediately observe:
(gdb) p bins
$3 = (int *) 0x7fffffffe390
although I fooled around with the formatting here (don't really know what I'm doing) and observed:
(gdb) p bins[0]
$5 = 1
(gdb) p bins[1]
$6 = 2
(gdb) p bins[2]
$5 = 3
(gdb) p bins[3]
$6 = 4
(gdb) p bins[4]
$5 = 5
(gdb) p bins[5]
$6 = 6
(gdb) p bins[6]
$5 = 7
(gdb) p bins[7]
$6 = 8
Why did gdb change the output of this array? Also, interesting (in a bad way), I see:
(gdb) p sizeof(bins)
$36 = 8
when it should be 4*8 = 32 (as I observe when doing this in file2).
Can someone help me understand what's happening to this array when it enters file3? (why it appears different here compared to just before it's passed into file3). I should mention the other arrays (aa, bb, cc) show the same behavior, although the scalars (dd, ee) come through fine in file3.

