[previous] 0492 [next] Array subscripting applied to a function parameter declared as a pointer.
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 a pointer which is a function parameter. This is perfectly legitimate in the C language providing the pointer addresses an array element; but some coding standards recommend that if a parameter refers to an array, it should be declared as an array.

Notice that message 0492 is only generated for function parameters. A function parameter declared as "array of type" is actually interpreted as a "pointer to type". 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 foo(int * pi1, int pi2[])
{
    int s;
    int t;

    s = pi1[3];                 /* 0492       */

    t = pi2[3];                 /* No message */

    return s + t;
}

See also:

QA·C Source Code Analyser 8.1.2
© 2013 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index Contents