MESSAGE
| DATE | 2011-06-05 |
| FROM | Ruben Safir
|
| SUBJECT | Subject: [NYLXS - HANGOUT] (fwd) Re: Anonymous namespace
|
From owner-hangout-outgoing-at-mrbrklyn.com Sun Jun 5 00:27:49 2011 Return-Path: X-Original-To: archive-at-mrbrklyn.com Delivered-To: archive-at-mrbrklyn.com Received: by www2.mrbrklyn.com (Postfix) id 87DFE100BCF; Sun, 5 Jun 2011 00:27:47 -0400 (EDT) Delivered-To: hangout-outgoing-at-www2.mrbrklyn.com Received: by www2.mrbrklyn.com (Postfix, from userid 28) id 7AE7C100B92; Sun, 5 Jun 2011 00:27:46 -0400 (EDT) Delivered-To: hangout-at-nylxs.com Received: from mailbackend.panix.com (mailbackend.panix.com [166.84.1.89]) by www2.mrbrklyn.com (Postfix) with ESMTP id 188CE100B88 for ; Sun, 5 Jun 2011 00:27:25 -0400 (EDT) Received: from panix2.panix.com (panix2.panix.com [166.84.1.2]) by mailbackend.panix.com (Postfix) with ESMTP id 528E132F10 for ; Sun, 5 Jun 2011 00:27:38 -0400 (EDT) Received: by panix2.panix.com (Postfix, from userid 20529) id 3C36433C5F; Sun, 5 Jun 2011 00:27:38 -0400 (EDT) From: Ruben Safir To: hangout-at-nylxs.com Subject: [NYLXS - HANGOUT] (fwd) Re: Anonymous namespace User-Agent: tin/1.8.3-20070201 ("Scotasay") (UNIX) (NetBSD/5.1 (i386)) Message-Id: <20110605042738.3C36433C5F-at-panix2.panix.com> Date: Sun, 5 Jun 2011 00:27:38 -0400 (EDT) Sender: owner-hangout-at-mrbrklyn.com Precedence: bulk Reply-To: hangout-at-mrbrklyn.com
-- forwarded message -- Path: reader1.panix.com!panix!newsfeed-00.mathworks.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Ian Collins Newsgroups: comp.lang.c++ Subject: Re: Anonymous namespace Date: Sat, 04 Jun 2011 15:57:57 +1200 Lines: 38 Message-ID: <94toq5FivcU2-at-mid.individual.net> References: <03464db0-e118-463c-9834-171dab457e42-at-h9g2000yqk.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net hY0Mz3iNUo7f794wMToOSgENRwAXOQEmaEK3ay1ibzI3usCyzi Cancel-Lock: sha1:/mSKmjsLAr/toxAmiU/H+cxzJPc= User-Agent: Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:1.9.2.9) Gecko/20101021 Lightning/1.0b2 Thunderbird/3.1.4 In-Reply-To: Xref: panix comp.lang.c++:1086000
On 06/ 4/11 01:44 AM, Victor Bazarov wrote: > On 6/3/2011 4:08 AM, gwowen wrote: >> On Jun 3, 3:54 am, r...-at-zedat.fu-berlin.de (Stefan Ram) wrote: >>>> What is the point of the anonymous namespace. >>> >>> Names can be hidden from the linker (from other translation >>> units), even if they should have external linkage. >> >> Can someone give the benefits of external-but-unlinkable anon- >> namespace variables (or functions) against old-school internal linkage >> file-scope "static" variables and functions. > > The Standard prohibits the use of names with no linkage or names with > internal linkage as template arguments. Only objects with external > linkage are allowed. Hence you can't use a function declared 'static' > or a local type as a predicate in 'std::sort', for instance, or as the > functor in 'std::for_each', and so on.
I was going to answer Ruben's last question with an example, but I couldn't find one that failed to compile with a static function!
This compiles file on everything I tried:
#include
static void test( int ) {} static bool test1( int, int ) { return true; }
int main() { int arr[4] = { 2,1,5,3 };
std::for_each( arr, arr+4, test ); std::sort( arr, arr+4, test1 ); }
-- Ian Collins -- end of forwarded message --
|
|