 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
tmartsum@gmail.com Guest
|
Posted: Mon Sep 26, 2005 2:53 pm Post subject: static - internal linkage |
|
|
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
|
Posted: Mon Sep 26, 2005 9:01 pm Post subject: Re: static - internal linkage |
|
|
[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 |
|
 |
|
|
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
|
|