C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Permit brace-encloded initializers for static consts in clas

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards
View previous topic :: View next topic  
Author Message
Ivan Godard
Guest





PostPosted: Mon May 24, 2004 3:48 pm    Post subject: Permit brace-encloded initializers for static consts in clas Reply with 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.

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





PostPosted: Tue May 25, 2004 9:49 pm    Post subject: Re: Permit brace-encloded initializers for static consts in Reply with quote



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





PostPosted: Wed May 26, 2004 2:46 am    Post subject: Re: Permit brace-encloded initializers for static consts in Reply with quote



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





PostPosted: Thu May 27, 2004 6:19 am    Post subject: Re: Permit brace-encloded initializers for static consts in Reply with quote

[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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.