array side-effect
der Mouse
mouse at thunder.mcrcim.mcgill.edu
Tue Jun 18 15:43:47 AEST 1991
In article <91165.095327PRD3 at psuvm.psu.edu>, PRD3 at psuvm.psu.edu writes:
> I have found a real stumper. Partial listing follows:
> int CODE_MATRIX[26][25]; //global
> char INMOD1[50][3]; //global
> int mod_loop=0; //local
> mod_loop++;
> INMOD1[mod_loop][0]="9"; //mod_loop is 1
> This last statement changes the value of CODE_MATRIX[26][1] from -9
> to some large random number.
It should provoke a compile-time complaint about assigning a pointer to
an integer ("9" is a pointer[%], but INMOD1[mod_loop][0] is an
integer[$]).
[%] Actually, an array, but in this context it immediately decays to a
pointer.
[$] I said integer, not int; "char" is one of the integer datatypes.
That aside, CODE_MATRIX[26][1] doesn't exist; the first subscript
ranges only 0..25. So when you access CODE_MATRIX[26][1] you could get
anything from a coredump to the current time of day in Uganda to (most
likely, in this case) two of the elements of INMOD1 packed together.
> I am using Borland Turbo C++ on a 386Clone running DOS.
Thank you for mentioning this; *nobody* seems to think to say what
machine and OS are in use anymore....
der Mouse
old: mcgill-vision!mouse
new: mouse at larry.mcrcim.mcgill.edu
More information about the Comp.lang.c
mailing list