From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1046 invoked by alias); 27 Jul 2010 23:55:03 -0000 Received: (qmail 957 invoked by uid 48); 27 Jul 2010 23:54:49 -0000 Date: Tue, 27 Jul 2010 23:55:00 -0000 Message-ID: <20100727235449.956.qmail@sourceware.org> X-Bugzilla-Reason: CC References: Subject: [Bug c++/45082] Static const signed int class member causes undefined symbol. In-Reply-To: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "redi at gcc dot gnu dot org" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2010-07/txt/msg03020.txt.bz2 ------- Comment #6 from redi at gcc dot gnu dot org 2010-07-27 23:54 ------- (In reply to comment #5) > Thanks for all the great comments and insight. > > I'm still confused as to why when the BUFF_SIZE was defined as: > static const signed int BUFF_SIZE = 20; > it caused the error, but when it was defined as: > static const unsigned int BUFF_SIZE = 20; > it did not. Because you can't bind const int& to an unsigned int, so a temporary is created and the reference bound to that. When the variable has type int the reference can bind to it directly. > There were 2 things that solved the problem I was seeing: > > 1. Adding a const signed int BUFF_SIZE; line to the .cpp file. > > I've seen lots of code where we define constants ala, static const int > BUFF_SIZE=20; in the .hpp file without any const int myclass::BUFF_SIZE; in the > .cpp files. Is that wrong to exclude them, should we be including them in the > .cpp file? Yes, if the variable is "used" in the program, see the reference from the standard that Jakub posted days ago in comment 1 > 2. Declaring the type during the call, ala, funky((int)myclass::BUFF_SIZE); You might have misunderstood that as well, there's no "declaring the type" there, it's creating a temporary which the reference binds to. > I'm not sure which is the better solution. Again, please follow up somewhere else, GCC's bugzilla is not the right place to learn the rules of C++. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45082