From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32439 invoked by alias); 10 Sep 2002 01:45:57 -0000 Mailing-List: contact gdb-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sources.redhat.com Received: (qmail 32425 invoked from network); 10 Sep 2002 01:45:54 -0000 Received: from unknown (HELO localhost.redhat.com) (216.138.202.10) by sources.redhat.com with SMTP; 10 Sep 2002 01:45:54 -0000 Received: from ges.redhat.com (localhost [127.0.0.1]) by localhost.redhat.com (Postfix) with ESMTP id 95D113F4A; Mon, 9 Sep 2002 21:45:54 -0400 (EDT) Message-ID: <3D7D4ED2.2050401@ges.redhat.com> Date: Mon, 09 Sep 2002 18:45:00 -0000 From: Andrew Cagney User-Agent: Mozilla/5.0 (X11; U; NetBSD macppc; en-US; rv:1.0.0) Gecko/20020824 X-Accept-Language: en-us, en MIME-Version: 1.0 To: David Carlton Cc: gdb Subject: Re: naive GDB programming style questions References: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2002-09/txt/msg00064.txt.bz2 > 1) It seems to me that some parts of GDB's source use NULL while other > parts use 0. Is one or the other of these generally preferred? > > 2) Am I correct in observing that GDB frowns on code like the > following: > > char *p = calculate_p (); > > if (!p) > p_is_zero (); I'll assume that you ment ``p_is_null()''. > preferring this instead? > > char *p = calculate_p (); > > if (p == NULL) > p_is_zero (); > > Does it matter that p in a pointer rather than an integer, or that > the code is testing for zeroness rather than nonzeroness? If you've a copy of the ISO C and C++ manuals, have a look at what they have to say about ``NULL'' pointers. It's weird. Anyway, for GDB, ``p == NULL'' is recommended to make it clear that the pointer is being tested and not the underlying value. > 3) Is it possible to get CC Mode to indent in the way that GDB seems > to prefer? I'm having a hard time getting structs to be indented > as follows: > > struct foo > { > int mem; > }; Just use: struct foo { int mem; }; which is what is output by gdb_indent.sh and emacs. The strange indentation that you've encountered dates back to an earlier version of indent. Must get around to sending the FSF coding standards group a patch that documents this (it was agreed to in principle some time ago). > without screwing up my preferred indentation when doing non-GDB > programming, namely > > struct foo { > int mem; > }; > > Of course, I can write functions to toggle between the two; but > given that both styles seem to be able to coexist for enums, maybe > it's possible to get them to coexist for enums. (I'm certainly no > CC Mode expert...) Andrew