From owner-freebsd-hackers Wed Nov 12 06:17:46 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.7/8.8.7) id GAA06103 for hackers-outgoing; Wed, 12 Nov 1997 06:17:46 -0800 (PST) (envelope-from owner-freebsd-hackers) Received: from mail.virginia.edu (mail.Virginia.EDU [128.143.2.9]) by hub.freebsd.org (8.8.7/8.8.7) with SMTP id GAA06095 for ; Wed, 12 Nov 1997 06:17:39 -0800 (PST) (envelope-from atf3r@cs.virginia.edu) Received: from ares.cs.virginia.edu by mail.virginia.edu id aa17697; 12 Nov 97 9:17 EST Received: from stretch.cs.virginia.edu (atf3r@stretch-fo.cs.Virginia.EDU [128.143.136.14]) by ares.cs.Virginia.EDU (8.8.5/8.8.5) with ESMTP id JAA07208; Wed, 12 Nov 1997 09:17:00 -0500 (EST) Received: (from atf3r@localhost) by stretch.cs.virginia.edu (8.8.5/8.8.5) id JAA11595; Wed, 12 Nov 1997 09:16:58 -0500 (EST) Date: Wed, 12 Nov 1997 09:16:58 -0500 (EST) From: "Adrian T. Filipi-Martin" Reply-To: adrian@virginia.edu To: Luigi Rizzo cc: hackers@freebsd.org Subject: Re: A stylistic question... In-Reply-To: <199711120858.JAA06510@labinfo.iet.unipi.it> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk On Wed, 12 Nov 1997, Luigi Rizzo wrote: > I have always wondered about this: most if not all programs, and some > pieces of the kernel as well (e.g. userconfig.c) > have a menu/usage function which is written like this: > > usage() > { > printf( "bla bla bla...\n" ); > printf( "bla bla bla...\n" ); > printf( "bla bla bla...\n" ); > ... > printf( "bla bla bla...\n" ); > } > > instead of what in my opinion would be much better: > > usage() > { > printf( "%s", "bla bla bla...\n" > "bla bla bla...\n" > ... > "bla bla bla...\n"); > } > > yes the code savings are modest (5-10 bytes/call ? but in the kernel > or boot blocks they still matter...) but at runtime the second > approach is faster since the format string must be parsed only once > and it is the shortest possible. > > Any reason not to use the second method ? Not really. It will compile into slightly smaller code and it will have better runtime performance since there will only one function call to printf(). Why do yo feel that you need the "%s" though? Just make the "blah..." your format string. The parsing of the format string is pretty efficient. It reads a char and then switch()'s on it to what to do. That's one comparison per character. Printing a string using "%s" will still need to do one comparison with each character when looking for '\0'. The overhead of the indexed jump is probably not worth worying about. Adrian -- adrian@virginia.edu ---->>>>| If I were stranded on a desert island, and System Administrator --->>>| I could only have one OS for my computer, Neurosurgical Visualzation Lab -->>| it would be FreeBSD. Think about it..... http://www.nvl.virginia.edu/ ->| http://www.freebsd.org/