[previous] 2021 [next] This tentative definition is interpreted as a declaration. Is this intended ?
Declarations and definitions

This is a tentative definition but it will be interpreted as a declaration because an explicit definition has been encountered elsewhere in the translation unit. Is this intended ?

A tentative definition is a file scope declaration of an object without an initializer and with no storage-class specifier except, possibly static. It is unconventional for such a declaration to be followed by an explicit definition. If this is intended to be a declaration with external linkage, it would be better practice to add 'extern'. If it is intended to be a declaration with internal linkage, is it really necessary ?

For example:


/*PRQA S 1306,3120,3207,3210,3211,3408,3447 ++*/

extern int ea;                /*              Declaration                                                              */
int eb = 5;                   /*              Explicit  definition                                                     */
int ec;                       /* Message 2022 Tentative definition -> definition with implicit initialization to zero  */
int ed;                       /* Message 2021 Tentative definition -> declaration                                      */
int ed;                       /* Message 2021 Tentative definition -> declaration                                      */
int ed = 5;                   /*              Explicit  definition                                                     */
int ee;                       /* Message 2021 Tentative definition -> declaration                                      */
extern int ee = 5;            /*              Explicit  definition                                                     */

static int sa;                /* Message 2022 Tentative definition -> definition with implicit initialization to zero  */
static int sb = 5;            /*              Explicit  definition                                                     */
static int sc;                /* Message 2022 Tentative definition -> definition with implicit initialization to zero  */
static int sd;                /* Message 2021 Tentative definition -> declaration                                      */
static int sd;                /* Message 2021 Tentative definition -> declaration                                      */
static int sd = 5;            /*              Explicit  definition                                                     */
static int se;                /* Message 2021 Tentative definition -> declaration                                      */
static int se = 5;            /*              Explicit  definition                                                     */

See also:

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