[RFC] -Wredundant-decls: keep it or remove it?

From: Craig Rodrigues (rodrigc_at_crodrigues.org)
Date: 08/10/05

  • Next message: Megan Felton: "GrandSlam St0ck"
    Date: Tue, 9 Aug 2005 20:53:23 -0400
    To: freebsd-arch@freebsd.org
    
    

    Hi,

    In recent days, while trying to get the kernel in shape to
    compile with GCC 4.0, I encountered some examples such as the
    following in net/rtsock.c:

    extern struct domain routedomain; /* or at least forward */

    static struct protosw routesw[] = {
    { SOCK_RAW, &routedomain, 0, PR_ATOMIC|PR_ADDR,
      0, route_output, raw_ctlinput, 0,
      0,
      raw_init, 0, 0, 0,
      &route_usrreqs
    }
    };

    static struct domain routedomain =
        { PF_ROUTE, "route", 0, 0, 0,
          routesw, &routesw[sizeof(routesw)/sizeof(routesw[0])] };

    It is illegal in ISO C to declare a struct as extern (implying external linkage)
    , and then declare it as static (implying internal linkage).

    I have two options to fix this.

    OPTION 1:

    Change routedomain to not be static:

    extern struct domain routedomain;

    ....
    struct domain routedomain = { ...... }

    OPTION 2:

    Forward declare routedomain as static, but remove -Wredundant-decls
    from kernel makefiles:

    static struct domain routedomain;

    ....
    static struct domain routedomain = { ..... }

    For OPTION 2, it is necessary to remove -Wredundant-decls
    because you will get a new compiler warning:

    warning: redundant redeclaration of 'routedomain'
    warnig: previous declaration was here ...

    To fix this problem, is it better to go with OPTION 1
    or OPTION 2? I am a bit hesitant to remove -Wredundant-decls
    from the kernel Makefiles, because it has been there for a long time.
    Are there cases where the warnings are useful?

    It seems to warn against legitimate C code in
    the GCC documentation:

    `-Wredundant-decls'
         Warn if anything is declared more than once in the same scope,
         even in cases where multiple declaration is valid and changes
         nothing.

    Any feedback would be appreciated.

    -- 
    Craig Rodrigues        
    rodrigc@crodrigues.org
    _______________________________________________
    freebsd-arch@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-arch
    To unsubscribe, send any mail to "freebsd-arch-unsubscribe@freebsd.org"
    

  • Next message: Megan Felton: "GrandSlam St0ck"

    Relevant Pages

    • Re: [patch 2.6.19-rc6] Stop gcc 4.1.0 optimizing wait_hpet_tick away
      ... wait_hpet_tick is optimized away to a never ending loop and the kernel ... This is not a problem with gcc 3.3.5. ... making the variables volatile does. ... needs to declare any variables that hold the result of hpet_readlas ...
      (Linux-Kernel)
    • PROBLEM: Badness in dst_release at include/net/dst.h:154
      ... If I only make a default route (the hard way - route add default gw ... the kernel oopses: ... declare -x EDITOR="nano" ... 000c8000-000c8fff: Adapter ROM ...
      (Linux-Kernel)
    • Re: how kernel stores data in structures?
      ... I want to know does that mean i can also declare ... > my structure in kernel and create its object as ... will keep this value until it is changed (obviously, global variables of ... Be aware that you are not protecting a variable by a spinlock but you ...
      (comp.os.linux.development.system)
    • Re: merge status
      ... > by leaving their patch sets until you declare a kernel, dumping the ... I think I'm noticing an uptick in patches as soon as a kernel is ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: [RFC] -Wredundant-decls: keep it or remove it?
      ... > It is illegal in ISO C to declare a struct as extern (implying external ... > static struct domain routedomain; ... > because you will get a new compiler warning: ...
      (freebsd-arch)