Query regarding warning removal when using extern

G

gaurav.dube

I am facing a problem with warning removal
I have got a header file it contains extern declarations of lot of
variables (say 100)
This header file is included in hundreds of .c files. Some of these .c
file contain definition of one the variable declared as extern in
header file. But since the header file is also included in this .c file
containing definition of variable, the compiler gives a warning . The
header file is common to hundreds of files ,so it is not possible to
remove extern declaration of variable from it, as it might be required
in other files.
Now my task is to remove these kind of warnings where a variable is
defined in the file and its extern is also declared in header file
included in this file. The code size is running into lakhs of lines.
 
T

Tom St Denis

I am facing a problem with warning removal
I have got a header file it contains extern declarations of lot of
variables (say 100)
This header file is included in hundreds of .c files. Some of these .c
file contain definition of one the variable declared as extern in
header file. But since the header file is also included in this .c file
containing definition of variable, the compiler gives a warning . The
header file is common to hundreds of files ,so it is not possible to
remove extern declaration of variable from it, as it might be required
in other files.
Now my task is to remove these kind of warnings where a variable is
defined in the file and its extern is also declared in header file
included in this file. The code size is running into lakhs of lines.

Um that shouldn't give a warning.

----
tom@bigbox ~ $ cat test.c
extern int a;

int a;


tom@bigbox ~ $ gcc -O2 -Wall -W -c test.c
----

Maybe your code gives warnings because you modify the type? e.g.

extern long a;

int a;

That will cause problems.

Or

extern long *a;

long a[100];

Will cause problems.

Tom
 
M

Morris Dovey

(e-mail address removed) (in
(e-mail address removed)) said:

| I am facing a problem with warning removal
| I have got a header file it contains extern declarations of lot of
| variables (say 100)
| This header file is included in hundreds of .c files. Some of
| these .c file contain definition of one the variable declared as
| extern in header file. But since the header file is also included
| in this .c file containing definition of variable, the compiler
| gives a warning . The header file is common to hundreds of files
| ,so it is not possible to remove extern declaration of variable
| from it, as it might be required in other files.
| Now my task is to remove these kind of warnings where a variable is
| defined in the file and its extern is also declared in header file
| included in this file. The code size is running into lakhs of lines.

The easy way is to remove the variable declaration from the file that
produces the warnings; and create a separate source file containing
the declaration. This will increase the linker workload but make the
compiler much happier.
 
E

Eric Sosman

I am facing a problem with warning removal
I have got a header file it contains extern declarations of lot of
variables (say 100)
This header file is included in hundreds of .c files. Some of these .c
file contain definition of one the variable declared as extern in
header file. But since the header file is also included in this .c file
containing definition of variable, the compiler gives a warning . The
header file is common to hundreds of files ,so it is not possible to
remove extern declaration of variable from it, as it might be required
in other files.
Now my task is to remove these kind of warnings where a variable is
defined in the file and its extern is also declared in header file
included in this file. The code size is running into lakhs of lines.

There is nothing wrong with declaring a variable with
the `extern' qualifier in the same compilation where that
variable is defined:

extern int fuzzball; /* legal declaration */
int fuzzball = 42; /* legal definition */

There *is* something wrong if the declaration and the
definition disagree:

extern char *string; /* legal declaration */
char string[100]; /* legal definition */
/* ... but the two are inconsistent, so the
* compiler will complain.
*/

What is the text of the warning message? Can you post
some actual code (shorter than lakhs of lines) that causes
the compiler to emit the message?
 
K

Keith Thompson

I am facing a problem with warning removal
I have got a header file it contains extern declarations of lot of
variables (say 100)
This header file is included in hundreds of .c files. Some of these .c
file contain definition of one the variable declared as extern in
header file. But since the header file is also included in this .c file
containing definition of variable, the compiler gives a warning . The
header file is common to hundreds of files ,so it is not possible to
remove extern declaration of variable from it, as it might be required
in other files.
Now my task is to remove these kind of warnings where a variable is
defined in the file and its extern is also declared in header file
included in this file. The code size is running into lakhs of lines.

A "lakh" is 100,000. (The term isn't widely used outside India.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top