I have a C code in which I have a structure declaration which has an array of int[576] declared in it.
For some reason, i had to remove this array from the structure, So I replaced this array with a pointer as int *ptr; declared some global array of same type, somewhere else in the code, and initialized this pointer by assigning the global array to this pointer. So I did not have to change the way I was accessing this array, from other parts of my code.
But it works fine/gives desired output when I have the array declared in the structure, but it gives junk output when I declare it as a pointer in the structure and assign a global array to this pointer, as a part of the pointer initialization.
All this code is being run on MS-VC 6.0/Windows setup/Intel-x86.
I tried below things:
Suspected structure padding/alignment but could not get any leads? If at all structure alignment could be a culprit how can i proceed to narrow it down and confirm it?
I have made sure that in both cases the array is initialized to some default values, say 0 before its first use, and its not being used before initialization.
I tried using global array as well as malloc based memory for this newly declared array. Same result, junk output.
How can I zero in on the problem? Any pointers would be helpful.