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 

static - internal linkage

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





PostPosted: Mon Sep 26, 2005 2:53 pm    Post subject: static - internal linkage Reply with quote



I was in a discussion on lang.com.c++ where I argued NOT to use static
i front of global variable....

(In C and older C++ programs the keyword static is (confusingly) used
to
mean "use internal linkage" (§B.2.3) Don't use static except inside
function (§7.1.2) and classes (§10.2.4)
from C++ programming language section 9.2.1
by Bjarne Stroustrup)

However somebody claimed that things had changed (or would soon) to
mean "use internal linkage". Is that true ?


---
[ 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
Tony
Guest





PostPosted: Mon Sep 26, 2005 9:01 pm    Post subject: Re: static - internal linkage Reply with quote




[email]tmartsum (AT) gmail (DOT) com[/email] wrote:
Quote:
I was in a discussion on lang.com.c++ where I argued NOT to use static
i front of global variable....

(In C and older C++ programs the keyword static is (confusingly) used
to
mean "use internal linkage" (§B.2.3) Don't use static except inside
function (§7.1.2) and classes (§10.2.4)
from C++ programming language section 9.2.1
by Bjarne Stroustrup)

However somebody claimed that things had changed (or would soon) to
mean "use internal linkage". Is that true ?



static has always, and still does, mean "use internal linkage". Many
people favour using unnamed namespaces instead, but I find static still
useful, because without static, most (all?) compilers still expose the
objects for external linkage (even though they will never be found) and
thus slow down your linking (although only noticeable on large
projects).

eg:

namespace
{
int foo;
int bar();

class Class { };
}

'foo' and 'bar' still have external linkage, but with a mangled-name
that includes the unique name of the unnamed namespace. So they
unnecessarily increase the size of the linker's symbol dictionary,
slowing down lookups and linking.

Instead use both 'static' and the namespace:

namespace
{
static int foo;
static int bar();

class Class { };
}

Of course, 'static' can't be used on the class, which makes the
namespace still useful...


---
[ 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.