🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #3717

Re: Static const data member initializers

#3717
From: Bill Gibbons
Date: Mon, 18 Mar 1996 17:51
41 lines
2249 bytes
In article <0099F84782C14100.3D6072A5@ittpub.nl>, "Wil Evers"
<wil@ittpub.nl> wrote:

> Does anyone know the rationale behind requiring a definition of a static
> const data member that has been declared with an initializer? I mean, if I
> write:
> 
>         // header file
> 
>         class X { static const int bufSize = 42; };
> 
> then why should I be required to write
> 
>         // some translation unit
> 
>         const int X::bufSize;
> 
> It seems to me that interpreting bufSize's declaration-with-initializer in
> the class definition as a definition in class scope with internal linkage
> (analogous to an inline member function) would make more sense.

But inline member functions have *external* linkage.  To make the ODR
(One Definition Rule) as useful as possible, it is necessary to enforce it
on all class members.

So the "make a copy in each file as needed" approach commonly used for
inline non-member functions will not work here - it would break the ODR.
And while there are ways to ensure that only one copy is actually used,
it was felt that requiring somewhat complex implementation tricks for
such a simple feature was inappropriate.

-- 
Bill Gibbons
bill@gibbons.org
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu 
]
Technical Details
Message-ID: <199603181725.JAA08503@shellx.best.com>
Path: arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austern
References: <0099F84782C14100.3D6072A5@ittpub.nl>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austern
From: bill@gibbons.org (Bill Gibbons)
Newsgroups: comp.std.c++
Subject: Re: Static const data member initializers
Date: 18 Mar 1996 09:51:23 PST
Organization: -none-
Approved: austern@isolde.mti.sgi.com
Message-ID: <199603181725.JAA08503@shellx.best.com>
References: <0099F84782C14100.3D6072A5@ittpub.nl>
NNTP-Posting-Host: isolde.mti.sgi.com
X-Original-Date: Mon, 18 Mar 1996 09:26:51 -0800
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBVAwUBMU2ip0y4NqrwXLNJAQExmAIAo0FMPLMjVGGH5kp0eEMxc6SCCe9yWhac
 BNmjhIOR/Smi8AMH+Q6F6ZEARlcYHwzeUgQRnah5i1fC42qptB7kcQ==
 =TXIH
Originator: austern@isolde.mti.sgi.com