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

Posted on 2007-10-02
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.
Question by:naseeam
    LVL 8

    Expert Comment

    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.

    LVL 53

    Expert Comment

    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.
    LVL 15

    Expert Comment

    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


    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 Comment

    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, under M32R.  I would like to get rid of this informational, if possible.

    Author Comment

    I already had include guards in the header file that extern's the variable.
    LVL 53

    Accepted Solution

    >> 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)

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
    This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
    The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
    The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now