Re: "PORTING C" > Viewing an array in wathc window fails!
Robby wrote:
int addNumbers(int fiveNumbers[])
{
int sum = 0;
int i;
for(i=0 ; i<5 ; i++) {
sum+=fiveNumbers[i];
}
return sum; //<<< BREAKPOINT HERE
}
=
==========================
====
When I stop at the breakpoint in the addNumbers() function, the value =
of sum
does equal 15, which means that the compiler is reading off *all* the =
correct
values from the fiveNumbers array. But why is it that we can't view =
the
contents of "fiveNumbers" array in the watch window like this:
The debugger has no way to know that fiveNumbers array contains five =
elements. After all, this would work just as well:
int array[10]={1,2,3,4,5,6,7,8,9,10};
y = addNumbers(array);
You could mention array dimensions in the function definition:
int addNumbers(int fiveNumbers[5]) { ... }
This also tells anyone reading the code that the function expects an =
array of exactly 5 elements. Barring that, you can tell the debugger how =
many elements you want to watch by entering "fiveNumbers,5" (without =
quotes) in the Watch window.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not =
necessarily a good idea. It is hard to be sure where they are going to =
land, and it could be dangerous sitting under them as they fly overhead. =
-- RFC 1925