From 7692496237838658579
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,942dd48e323646a4
X-Google-Attributes: gidf78e5,public
From: Steve Clamage <stephen.clamage@sun.com>
Subject: Re: const static member in a class
Date: 2000/05/28
Message-ID: <392EF78C.785F7011@sun.com>#1/1
X-Deja-AN: 627960350
Content-Transfer-Encoding: 7bit
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
References: <3908CCBC.E02307C@hotmail.com> <jRZNYBDqKCC5Ewpe@robinton.demon.co.uk> <392E5925.6BABB160@gmx.de>
X-Accept-Language: en
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
Content-Type: text/plain; charset=us-ascii
X-Complaints-To: abuse@demon.net
X-Mail2News-Path: news.demon.net!mulga.cs.mu.oz.au
X-Trace: mail2news.demon.co.uk 959437690 mail2news:6977 mail2news mail2news.demon.co.uk
Organization: Sun Microsystems
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
Mime-Version: 1.0
Newsgroups: comp.std.c++

Ole Reinartz wrote:
> 
> Francis Glassborow wrote:
> 
> > In article <3908CCBC.E02307C@hotmail.com>, Yaxun Liu
> > <yx_liu@hotmail.com> writes
> > >
> > >class A
> > >{
> > >public:
> > >static const int m_a=1;
> > >};
> > >
> >
> > This one is not really MS's fault as in class initialisation of static
> > const data (integer types only) was a late tweak to the Standard.  In
> > addition you still have to define the variable exactly once somewhere in
> > your program (for the linker)
> >
> 
> AFAIK in that special case you dont even have to define it for the linker
> somewhere, because it is a constant. Because it will never change it doesnt
> have to have a fixed location.

Suppose you take its address -- explicitly, or by passing it via a
reference parameter.  It then needs a location in memory.  The
compiler can't just create a temp on the fly, because if you take its
address in different translation units, the addresses must compare
equal (it has external linkage).

If you don't "use" the member, it doesn't need a definition. Otherwise,
the standard says the results are undefined unless you provide exactly
one definition in the program -- the same as for any object with
external linkage.

-- 
Steve Clamage, stephen.clamage@sun.com

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]




