From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1711 invoked by alias); 30 Apr 2008 09:03:38 -0000 Received: (qmail 1514 invoked by uid 22791); 30 Apr 2008 09:03:34 -0000 X-Spam-Check-By: sourceware.org Received: from relay1.mail.uk.clara.net (HELO relay1.mail.uk.clara.net) (80.168.70.181) by sourceware.org (qpsmtpd/0.31) with ESMTP; Wed, 30 Apr 2008 09:03:07 +0000 Received: from [217.20.22.66] (helo=SPIRITBEAR) by relay1.mail.uk.clara.net with esmtpa (Exim 4.62) (envelope-from ) id 1Jr8DO-0002tW-6F; Wed, 30 Apr 2008 10:03:02 +0100 From: "Rupert Wood" To: "'me22'" , "'Robert William Fuller'" Cc: References: <481785A7.3060506@mit.edu> <00b701c8aa51$ef2c9b50$cd85d1f0$@net> <4817BD31.5000402@gmail.com> In-Reply-To: Subject: RE: OT Rant on why C++ Sucks (Was Re: strict aliasing: how to swap pointers) Date: Wed, 30 Apr 2008 10:21:00 -0000 Message-ID: <014b01c8aaa0$fe8a39a0$fb9eace0$@net> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Office Outlook 12.0 Content-Language: en-gb X-Clara-Relay: Message sent using Claranet Relay Service using auth code: postmaster@rupey.net X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2008-04/txt/msg00403.txt.bz2 me22 wrote: > > > Not turning on inlining? What a great idea! It's obviously better to > do a function call for a tiny little operation than to just inline the > code. Why, that way the functions even show up! That must be better > than stripping it from the binary since it's never called. Who needs > strong static type safety, anyways? > > I agree, code like this should probably get inlined (or at least be availab= le to the optimizer to inline if it wants) but even if it's not the compile= r doesn't actually need to instantiate a new exchange method for every type. All pointers are the same size (modulo funny platforms) and copying a point= er is the same operation regardless of what it points to (modulo smart poin= ters). So the actual exchange operation is always the same, so the assembly= generated for all instances of this method will be the same, and so the co= mpiler only need emit one copy of exchange and reuse it for all calls. Even= if exchange operated opaquely on types and structures rather than pointers= it would only need one instance for types sizeof =3D=3D 4, one for types s= izeof =3D=3D 8 etc. Rup.