From owner-freebsd-hackers@FreeBSD.ORG Sun Mar 21 00:46:09 2004 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 29CBF16A4CE for ; Sun, 21 Mar 2004 00:46:09 -0800 (PST) Received: from mail003.syd.optusnet.com.au (mail003.syd.optusnet.com.au [211.29.132.144]) by mx1.FreeBSD.org (Postfix) with ESMTP id CD24443D2D for ; Sun, 21 Mar 2004 00:46:07 -0800 (PST) (envelope-from peterjeremy@optushome.com.au) Received: from server.vk2pj.dyndns.org (c211-30-75-229.belrs2.nsw.optusnet.com.au [211.30.75.229]) i2L8jn416341; Sun, 21 Mar 2004 19:45:50 +1100 Received: from server.vk2pj.dyndns.org (localhost.vk2pj.dyndns.org [127.0.0.1])i2L8jiNa048118; Sun, 21 Mar 2004 19:45:44 +1100 (EST) (envelope-from peter@server.vk2pj.dyndns.org) Received: (from peter@localhost) by server.vk2pj.dyndns.org (8.12.10/8.12.10/Submit) id i2L8jhUc048117; Sun, 21 Mar 2004 19:45:43 +1100 (EST) (envelope-from peter) Date: Sun, 21 Mar 2004 19:45:43 +1100 From: Peter Jeremy To: Matt Emmerton Message-ID: <20040321084543.GA48068@server.vk2pj.dyndns.org> References: <002f01c40f14$f4406540$1200a8c0@gsicomp.on.ca> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <002f01c40f14$f4406540$1200a8c0@gsicomp.on.ca> User-Agent: Mutt/1.4.2.1i cc: hackers@freebsd.org cc: Garance A Drosihn Subject: Re: Adventures with gcc: code vs object-code size X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 21 Mar 2004 08:46:09 -0000 On Sun, Mar 21, 2004 at 02:20:13AM -0500, Matt Emmerton wrote: > >----- Original Message ----- >From: "Garance A Drosihn" >To: >Sent: Saturday, March 20, 2004 5:45 PM >Subject: Adventures with gcc: code vs object-code size >> if (strcmp(elemcopy, ":") == 0) ... >I don't know why the code bloats so much on i386, but I do question the use >of strcmp() for a single-character compare. >Something like the following would probably be better (and would avoid your >problem): > >if (elemcopy[0] == ':') > inf->count = 0; >else > inf->addelem(inf, elemcopy); That code isn't equivalent in general. Your code just checks that the first character is ':'. It doesn't verify that the string is exactly one character long. It's possible that in this particular context, elemcopy may be constrained such that it must be ":" if the first character is ':' but this isn't clear from Garances posting. The equivalent code would be: if (elemcopy[0] == ':' && elemcopy[1] == '\0') inf->count = 0; else inf->addelem(inf, elemcopy); But (IMHO) this is a lot less clear than the former code (thought I admit I'm guilty of doing this quite a lot in my code). Note that a modern C compiler is free to convert strcpy(elemcopy, ":") == 0 into elemcopy[0] == ':' && elemcopy[1] == '\0' assuming the relevant header () is in scope. (I was under the impression that gcc did this). Peter