By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,369 Members | 1,207 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,369 IT Pros & Developers. It's quick & easy.

Query regarding warning removal when using extern

P: n/a
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.

Jul 18 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a

ga*********@gmail.com wrote:
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

Jul 18 '06 #2

P: n/a
ga*********@gmail.com (in
11*********************@h48g2000cwc.googlegroups.c om) 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.

--
Morris Dovey
DeSoto Solar
DeSoto, Iowa USA
http://www.iedu.com/DeSoto
Jul 18 '06 #3

P: n/a


ga*********@gmail.com wrote On 07/18/06 13:34,:
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?

--
Er*********@sun.com

Jul 18 '06 #4

P: n/a
ga*********@gmail.com writes:
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.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jul 18 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.