![]() |
![]() |
0491 | ![]() |
||||
![]() | |||||||
| Pointers | REFERENCE - ISO:C90-6.3.2.1 Array Subscripting, ISO:C90 6.2.2.1 Lvalues and Function Designators, ISO:C90 6.7.1 Function Definitions - Semantics | ||||||
An array subscript operator is being used to subscript an expression which is not of array type. This is perfectly legitimate in the C language providing the pointer addresses an array element; but may be discouraged in some coding standards which seek to restrict the use of pointers. The array subscript operator requires 2 operands, one of pointer to object type and the other of integral type, and the effect is to add the integer value to the pointer value. If the pointer operand is an expression of array type, it is automatically converted to a pointer which addresses the first element of the array. Message 0492 is generated instead of message 0491 when the pointer is a function parameter explicitly defined as a pointer. A function parameter declared as "array of type" is actually interpreted as a "pointer to type". So, in the code shown below, the function parameters "pi1" and "pi2", although declared with different syntax, are actually both of type "pointer to int" For example:
/*PRQA S 506,2213,3196,3120,3203,3227,3408,3447,3673 ++*/
extern int * gpi;
extern int foo(int * pi1, int pi2[])
{
int r;
int s;
int t;
r = gpi[3]; /* 0491 */
s = pi1[3]; /* 0492 */
t = pi2[3]; /* No message */
return r + s + t;
}
See also:
![]() | ||
| QA·C Source Code Analyser 8.1.2
© 2013 Programming Research. www.programmingresearch.com | Personality Groups | Glossary | Message Index | Contents |