We help IT Professionals succeed at work.

Why compiler gives warning for identical declaration of variable, when it's only declared once?

naseeam
naseeam asked
on
324 Views
Last Modified: 2012-06-21
I am using Renesas compiler to compile some.c file.  In some.c file, I define array variable fdd_types.  This fdd_types array is externed in a header file which is included in some.c file.  So I have declared the variable only once.  Why does compiler give following information that there is prior identical declaration.
Also, in the same header file there are some macros that have this variable.  One of the macros is as follows:

#define fdd_write( dev, addr, \
    data, len,  mode ) \
    (fdd_types[(dev)].write((addr), (data), (len), (mode)))

This macro is not called in the some.c file.  It is called from some other .c file.

The information message from compiler is as follows:

"..\..\..\src\lib\fdd_b4m1i2\..\fdd\fdd_types.c", line 205: information: fdd_typ
es: prior identical declaration -- ignored

Please advise.  Thanks.
Comment
Watch Question

Strange, because the informational message says the file that contains the problem is fdd_types.c line 205. What does that line from fdd_types.c look like.

CERTIFIED EXPERT
Top Expert 2009

Commented:
Can you try to compile this simple code with the same compiler (and the same compiler flags) ,

        extern int some_val;
       
        int some_val = 5;
       
        int main(void) {
            return 0;
        }

Does it generate the same warning ? If so, then don't worry about it. You can avoid it by NOT including the extern line for some_val in the .c file where some_val is declared :

        /* extern int some_val; */
       
        int some_val = 5;
       
        int main(void) {
            return 0;
        }

Btw, it does say that the warning is information only, so there's no problem for the compiler.

Commented:
This is almost certainly caused by a duplicate include. In your include file, surround the contents with:

#if !defined(fdd_include_h)
#define fdd_include_h 1

... put the original contents of the file here

#endif

I always encapsulate include files like this, just to be sure they'll work OK, even if someone accidentally does a multiple include.

Typically the file can be included from another include file (or even from another file that's included from another include file, etc.). One golden rule: if you can avoid it, never include a file in an include file, otherwise you run the risk of hitting this problem.

Author

Commented:
My mistake.  I'm not compling some.c file.  I'm compiling fdd_types.c file.


When compile above code with the same compiler (and the same compiler flags), I get the same warning.  What's puzzling me is that my peer is using the exact same compiler and It beleive same compiler flags.  He doesn't get the informational warning when he compiles.  
Compiler Documentation is at www.renesas.com, under M32R.  I would like to get rid of this informational, if possible.

Author

Commented:
I already had include guards in the header file that extern's the variable.
CERTIFIED EXPERT
Top Expert 2009
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.