BIND 10 #2358: DBGLVL_xxx should be in .cc, and in specific name space

BIND 10 Development do-not-reply at isc.org
Mon Oct 15 22:52:37 UTC 2012


#2358: DBGLVL_xxx should be in .cc, and in specific name space
-------------------------------------+-------------------------------------
                   Reporter:         |                 Owner:
  jinmei                             |                Status:  new
                       Type:         |             Milestone:  Next-Sprint-
  defect                             |  Proposed
                   Priority:         |            Resolution:
  medium                             |             Sensitive:  0
                  Component:         |           Sub-Project:  Core
  logging                            |  Estimated Difficulty:  0
                   Keywords:         |           Total Hours:  0
            Defect Severity:  N/A    |
Feature Depending on Ticket:         |
        Add Hours to Ticket:  0      |
                  Internal?:  0      |
-------------------------------------+-------------------------------------
Description changed by jinmei:

Old description:

> `DBGLVL_xxx` constants defined in log_dbglevels.h break a couple of
> fundamental rules of C++.
>
> - It shouldn't be in unnamed namespace (`namespace {}`).  Having it in
>   a shared header file easily leads to breaking the one definition
>   rule.
> - It shouldn't be defined in the header file.  Since they are
>   constants smart linkers may avoid generating duplicate copies, but
>   as far as I know it's not guaranteed by the language.
>
> Solution is easy:
>
> - Declare them in a specific namespace, like isc::log
> - Only declare them in the header file; define them in a separate .cc:
>
> {{{#!cpp
> // in log_dbglevels.h
> // This is BAD
> //const int DBGLVL_START_SHUT = 0;
> extern const int DBGLVL_START_SHUT;
> }}}
>
> {{{#!cpp
> // in log_dbglevels.cc
> const int DBGLVL_START_SHUT = 20;
> }}}

New description:

 `DBGLVL_xxx` constants defined in log_dbglevels.h break a couple of
 fundamental rules of C++.

 - It shouldn't be in unnamed namespace (`namespace {}`).  Having it in
   a shared header file easily leads to breaking the one definition
   rule.
 - It shouldn't be defined in the header file.  Since they are
   constants smart linkers may avoid generating duplicate copies, but
   as far as I know it's not guaranteed by the language.

 Solution is easy:

 - Declare them in a specific namespace, like isc::log
 - Only declare them in the header file; define them in a separate .cc:

 {{{#!cpp
 // in log_dbglevels.h
 // This is BAD
 //const int DBGLVL_START_SHUT = 0;
 extern const int DBGLVL_START_SHUT;
 }}}

 {{{#!cpp
 // in log_dbglevels.cc
 const int DBGLVL_START_SHUT = 0;
 }}}

--

-- 
Ticket URL: <http://bind10.isc.org/ticket/2358#comment:1>
BIND 10 Development <http://bind10.isc.org>
BIND 10 Development


More information about the bind10-tickets mailing list