From owner-freebsd-questions@FreeBSD.ORG Tue Mar 31 19:01:50 2009 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5B0B91065670 for ; Tue, 31 Mar 2009 19:01:50 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mx02.qsc.de (mx02.qsc.de [213.148.130.14]) by mx1.freebsd.org (Postfix) with ESMTP id E24168FC21 for ; Tue, 31 Mar 2009 19:01:49 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from r55.edvax.de (port-92-196-37-253.dynamic.qsc.de [92.196.37.253]) by mx02.qsc.de (Postfix) with ESMTP id 0D1DE16C01B2; Tue, 31 Mar 2009 21:01:47 +0200 (CEST) Received: from r55.edvax.de (localhost [127.0.0.1]) by r55.edvax.de (8.14.2/8.14.2) with SMTP id n2VJ1g2T001501; Tue, 31 Mar 2009 21:01:42 +0200 (CEST) (envelope-from freebsd@edvax.de) Date: Tue, 31 Mar 2009 21:01:42 +0200 From: Polytropon To: Gary Kline Message-Id: <20090331210142.7dcb52ec.freebsd@edvax.de> In-Reply-To: <20090331155416.GA8590@thought.org> References: <20090331025726.GA10888@thought.org> <20090331112122.ae329221.freebsd@edvax.de> <20090331155416.GA8590@thought.org> Organization: EDVAX X-Mailer: Sylpheed 2.4.7 (GTK+ 2.12.1; i386-portbld-freebsd7.0) Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: FreeBSD Mailing List Subject: Re: Why?? (prog question) X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Polytropon List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 31 Mar 2009 19:01:51 -0000 On Tue, 31 Mar 2009 08:54:17 -0700, Gary Kline wrote: > > 1. Use the tab character for indentation. You can set its > > length with your favourite editor (e. g. mcedit: F9, > > Options, General; joe: ^TD). Don't waste with spaces. >=20 > Ja, been doing this since 1978. Does anybody hit space-key=20 > 8 times!? I've seen "corporate guideline" for indentation =3D 10 spaces. Used ^TD8 and then finally replace tab -> ' '. :-) > > 2. The main() function should be declared as > > int main(int argc, char *argv[]) > > or > > int main(int argc, char **argv) > > Note that it's returning (int). Use this functionality. >=20 > I've come to prefer the *char argv[] ... I didn't use the formal int > return because this was supposed throwaway code. (Going on years now > tho, so ... my-bad.) The standard assumption of the return code is (int), so if it's not declared, it's (int) anyway. > > 4. Use the predefined return codes, don't hardcode them. > > FreeBSD has EXiT_SUCCESS and EXIT_FAILURE, they're for > > maximum compatibility (such as with Linux). There are > > more exit codes for differentiation, but they're specific > > to FreeBSD, as far as I know. >=20 > This I did not know. I have a prefab include file with a bunch=20 > of my own similar #defines. Wow, great! FreeBSD defines additional exit codes to specify the reason for exiting more precisely in /usr/include/sysexits.h - for your example, exit(EX_USAGE); would be a good exit code. I don't know how far this is adopted in Linux, but I think you can only use the C99 two standard return codes. >From "man 3 exit": The C Standard (ISO/IEC 9899:1999 (``ISO C99'')) defines the values 0, EXIT_SUCCESS, and EXIT_FAILURE as possible values of status.=20 > > 5. This is highly debatable: Use a good style for { and }. > >=20 >=20 > Well, you're using the K&R { }; but for me, the "Ingres" > style [[ yes, it was invented by someone else ]] gets my vote. > I scan > { > and > } >=20 > more easily. 6 of one, half-dozen of another... . In fact, I'm sticking to the concept that only the highest level of "code groupers" deserve a new line {: these are functions in C and class methods in C++. Everything else has the { appended (after a space) to the construct that causes the {. So if you find a }, you only need to look up. It's obvious that a } is caused by a {, but you want to know the construct that made it appear, for example if(), while(), a struct definition or something similar. With this concept at hand, looking up will make you find this construct in question at the first glance. You could see this in the example. But as we'll all agree, this is a thing of individual preference. > > Here is the program again, with some stylistic modifications > > and the "correct" (read: recommended, usual) exit code handling: >=20 > I'll swipe this. I use this code with openoffice and abiword > because I compose with vi; but I almost always forget to run=20 > my text thru joinlines and have to quit the word processor, run > jlines bar; mv bar foo; then restart the word processor. > I figure that I've spend several centuries of my lifetime messing=20 > with jlines, so i'm overdue for doing it right.... I think OpenOffice has the function Input - from file (at least the german version has: Alt-E D =3D Einf=FCgen Datei). This makes it easier to incorporate text from an external file. --=20 Polytropon >From Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...