Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 309
  • Last Modified:

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

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.
0
naseeam
Asked:
naseeam
1 Solution
 
Anthony2000Commented:
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.

0
 
Infinity08Commented:
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.
0
 
bpmurrayCommented:
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.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
naseeamAuthor 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.
0
 
naseeamAuthor Commented:
I already had include guards in the header file that extern's the variable.
0
 
Infinity08Commented:
>> I would like to get rid of this informational, if possible.

Well, you can just remove the extern from the .c file. Something like this should help :

---- fdd_types.h ----

#ifndef FDD_TYPES_H
#define FDD_TYPES_H

#ifndef FDD_TYPES_C
extern int some_val;
#endif /* FDD_TYPES_C */

/* the rest of the header */

#endif /* FDD_TYPES_H */

---- ----

---- fdd_types.c ----

#define FDD_TYPES_C
#include "fdd_types.h"

int some_val = 5;

/* rest of c file */

---- ----

This will avoid adding the extern statement to the source file that defines the variable. (of course you have to change the definition of the externed variable, but I'm sure you see what I mean)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now