 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Ivan Godard Guest
|
Posted: Mon May 24, 2004 3:48 pm Post subject: Permit brace-encloded initializers for static consts in clas |
|
|
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 ]
|
|
| Back to top |
|
 |
Graeme Prentice Guest
|
Posted: Tue May 25, 2004 9:49 pm Post subject: Re: Permit brace-encloded initializers for static consts in |
|
|
On Mon, 24 May 2004 15:48:16 +0000 (UTC), "Ivan Godard" wrote:
| Quote: | 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 ]
|
|
| Back to top |
|
 |
Hyman Rosen Guest
|
Posted: Wed May 26, 2004 2:46 am Post subject: Re: Permit brace-encloded initializers for static consts in |
|
|
Graeme Prentice wrote:
| Quote: | 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 ]
|
|
| Back to top |
|
 |
llewelly Guest
|
Posted: Thu May 27, 2004 6:19 am Post subject: Re: Permit brace-encloded initializers for static consts in |
|
|
[email]hyrosen (AT) mail (DOT) com[/email] (Hyman Rosen) writes:
| Quote: | 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.
|
This seems to be yet another place where a new feature (static members
of class templates) required increased support from an
implementation, but restrictions on an older feature (static
members of classes) meant to avoid similar increased support were
not relaxed.
---
[ 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 ]
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|