C code - declaring global variable

Flaviu_ 971 Reputation points
2023-05-12T16:02:04.7933333+00:00

I have a legacy code:

// file3.h
extern int g_index;

// file3.c

int g_index= -1;

// file1.c

gindex = some_value;

Compiles and works fine. But, the quality tools says:

Don't use extern variable declarations in header files, except for consts.

How can I overcome this ?

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,633 questions
{count} votes