Topic: Static initialization


Author: "Victor Bazarov" <vAbazarov@dAnai.com>
Date: 28 Aug 2002 17:25:04 GMT
Raw View
"Anthony Williams" <anthwil@nortelnetworks.com> wrote...
> In 3.6.2p1, the Standard says "Zero-initialization and initialization with
a
> constant expression are collectively called static initialization; all
other
> initialization is dynamic initialization."
>
> Consider the following code:
>
> struct A
> {
>     int data;
>
>     A():
>         data(1)
>     {}
> };
>
> A a;
>
> Is a.data "initialized with a constant expression", and thus statically
> initialized, or is the fact that it is part of a class object, which is
not
> initialized with a constant expression, enough to make it dynamic
> initialization?

'data' is a local object.  3.6.2 talks about non-local objects.

>
> Now consider:
>
> struct B
> {
>     int data;
>
>     B(int i):
>         data(i)
>     {}
> };
>
> B b(1);
>
> In this case, b is initialized with a constant expression. Does it
therefore
> qualify for static initialization, even though b is of class type?

If the above code exists on a namespace level, then yes, 'b' is
statically initialised.  At least that's how I read 3.6.2...

Victor
--
Please remove capital A's from my address when replying by mail


---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]