CompuServe Thread

#Array dim bugs

3 messages in this thread
#50295From: Mark F. DavisJul 31, 1993 10:23 PM
A general debugging question if I may: Suppose the sources of an NT C program are split between 2 files. Suppose the 1st file declares a 1 dimensional array: int ary [10]; Suppose the 2nd file incorrectly references the array as 2 dimensional: extern int ary [] [8]; This is clearly a bug, but neither the compiler nor the linker catch it. If the array were declared in a .h file included by both .c files, the compiler would catch it, but the extra include file isn't necessary for syntactically correct C code, and without it the bug goes unreported, even at run time. Is there a mechanism provided in the NT debugger for automatically identifying such bugs? — Mark There is 1 Reply.
#50547From: Julie Solon [Microsoft]Aug 3, 1993 1:28 PM
Mark, > This is clearly a bug, but neither the compiler nor the linker catch it This is actually not a bug. The compiler is going to check that you reference each variable in a way that is consistent with the its declaration in that file. When you put "extern" in front of the definition, the linker assumes that the declaration refers to a definition in another file. If there is no external definition, the linker will allocate the storage. If there is more than one declaration, storage is allocated for the largest of the declarations. I don't know of an elegant way to track down such bugs in the code using a debugger. If declarations are put in a header file, it is less likely that mistakes like this will be made. Sincerely, Julie Solon Microsoft Developer Support There is 1 Reply.
#50575From: Mark F. DavisAug 3, 1993 2:16 PM
>> I don't know of an elegant way to track down such bugs .. Actually, the CenterLine (former Sabre) C debugger quite reliably reports such bugs, it just doesn't work under NT (it's a Unix app). An NT debugger with similar capabilities would be highly desirable. — Mark