In this section:
This error is generated whenever a function parameter is declared as an array but has more elements than the actual argument that was passed.
Array parameter exceeded range
The following code fragment shows an array declared with one size in the
main routine and then used with another in a function.
Diagnosis at Runtime
- Line 2: Source file and line at which the problem was detected.
- Line 3: Description of the problem and the name of the parameter that is in error.
- Line 4: Schematic showing the relative layout of the memory block which was actually passed as the argument (b) and expected parameter (p). Also see Overflow Diagrams.
- Line 7: Description of the memory range occupied by the parameter, including its length.
- Line 10: Description of the actual block of data corresponding to the argument, including its address range and size. Also includes the name of the real variable which matches the argument and the line number at which it was declared.
- Line 13: Stack trace showing the function call sequence leading to the error.
This error is normally easy to correct based on the information presented in the diagnostic output. The simplest solution is to change the definition of the array in the called routine to indicate an array of unknown size, i.e., replace line 5 with the following:
parmrnge.c, 5 int a;
This declaration will match any array argument and is the recommended approach whenever the called routine will accept arrays of variable size.
An alternative is to change the declaration of the array in the calling routine to match that expected. In this case, line 10 could be changed to the following, which would match the argument declaration:
parmrnge.c, 10 int b;