Topic: Permit brace-encloded initializers for static consts in class scope
Author: Graeme Prentice <gprenz@hotmail.com>
Date: Tue, 25 May 2004 15:49:58 CST Raw View
On Mon, 24 May 2004 15:48:16 +0000 (UTC), "Ivan Godard" wrote:
>class Foo {
>static const int s = 3;
>static const int f[] = {1,2,3};
>static const int w[];
> };
>static const int w[] = {4,5,6};
>
>Here "s" and "w" are legal, but "f" is not. Forcing a seperate definition
>outside the class seems pretty pointless. The example that prompted this
>note is a FSM class with a bunch of small constant transition tables.
It's not pointless. The definition outside the class is required so
that the compiler can know when to allocate storage and initialization
code. Because the class definition can appear in multiple translation
units, if the compiler allocated storage and initialization code in
every translation unit, each translation unit would have its own copy of
the array or member, unless the linker was able to remove multiple
occurrences - this is probably a pain for the compiler and linker to
arrange and it also removes the choice from the programmer of which
module contains the object.
BTW "s" may require a definition if you or the compiler uses its
address.
Graeme
---
[ 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 ]
Author: hyrosen@mail.com (Hyman Rosen)
Date: Wed, 26 May 2004 02:46:41 +0000 (UTC) Raw View
Graeme Prentice wrote:
> if the compiler allocated storage and initialization code in
> every translation unit, each translation unit would have its own copy of
> the array or member, unless the linker was able to remove multiple
> occurrences
This is already required behavior for templates,
so it could work just as easily for classes.
---
[ 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 ]
Author: igodardA@TpacbellDO.Tnet ("Ivan Godard")
Date: Mon, 24 May 2004 15:48:16 +0000 (UTC) Raw View
class Foo {
static const int s = 3;
static const int f[] = {1,2,3};
static const int w[];
};
static const int w[] = {4,5,6};
Here "s" and "w" are legal, but "f" is not. Forcing a seperate definition
outside the class seems pretty pointless. The example that prompted this
note is a FSM class with a bunch of small constant transition tables.
Ivan
---
[ 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 ]