[previous] 3204 [next] The variable '%s' is only set once and so it could be declared with the 'const' qualifier.
Declarations and Definitions REFERENCE - ISO:C90-6.5.3 Type Qualifiers

The value of this local variable is only set once - either through initialisation or assignment. Perhaps it would be better to initialise it when it is defined and apply the 'const' type qualifier.

'const' can be applied to any variable whose value needs to be set only once providing it can be initialized when it is defined.

For example:


/*PRQA S 2017,3120,3122,3123,3198,3199,3203,3408,3447,3602,3604,3625,3674 ++*/

extern int foo(const char * const pc);

extern int f1(int s)                                 /* Message 3227        */
{
    char               a      = 'a';                 /* Message 3204        */

    char       *       str0   = "Hello 0";           /* Message 3204 + 0753 */
    const char *       str1   = "Hello 1";           /* Message 3204        */
    const char * const str2   = "Hello 2";           /*                     */
    char       * const str3   = "Hello 3";           /*                0753 */

    char               str4[] = "Hello 4";           /* Message 3204        */

    int                r;
    int                x;                            /* Message 3204        */
    char               c;

    x = 2;
    r = x + s;
    c = a;
    r = foo(str0);
    r = foo(str1);
    r = foo(str2);
    r = foo(str3);
    c = str4[0];

    return r;
}

See also:

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