🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.unix.programmer
2 messages
2 total messages Started by Ed Skinner Thu, 11 Oct 1990 16:41
Catch Source Code Errors - Tricks Wanted
#980
Author: Ed Skinner
Date: Thu, 11 Oct 1990 16:41
56 lines
2990 bytes
     Do you have a trick or two for polishing and/or debugging "C"
code using typical Unix(tm) tools?  I am interested in anything that
helps locate coding errors, particularly those techniques that use
programs available on run-of-the-mill Unix-based systems.
     I am making a collection and will post it to the net.  Please mail
your submissions instead of posting them to this group.

     Here is an example of what I'm looking for;

     I use cb(1) and diff(1) to catch what I'll call grouping or indentation
problems.  I fall into this trap when my first version of code has a single
statement inside an if-statement's true clause and then I later go back and
add another line or two of code.

fragment()
{
	if (moveit(datap, dev) == 0)
		assert(dvcp->c_res == 0);                   <----- ADDED LINE
		if (dvcp->c_flags & ASYNC) {
			status = q_send(dvcp->c_id, &end);
			assert((status == E_NOERR) || (status == E_OBJDEL));
		}
}

     Both versions will compile and lint(1) (in the full version, not the
fragment I've shown above) without detecting the error.  Visually, the
second if-statement version is within the first if-statement's true clause.
However, the compiler ignores indentation and generates the second
if-statement code completely outside of the first.
     I recently spent two days tracking down one of these errors!

"Fool me once, shame on you [the compiler].  Fool me twice, shame on me!"

     Using cb(1) and diff(1), I developed a quick check that will find
this type of error.

     Briefly, the source file is "beautified" and compared to the original.
Any differences, such as in the amount of indentation I think is necessary
versus what cb(1) thinks is needed are pointed out by diff(1).

          cb $f | diff - $f

     One drawback, of course, is that the source file must be coded in
a cb(1) format in order to use cb(1) to "find" differences between what
I mean and what the compiler will understand.  This format may not conform
with your favorite style, nor that of your employer.  However, I am willing
to change my habits (and style) when I find something that will help me
generate better code in less time.

-- 
"Wisdom is the absence of ideals."  Chinese proverb
#include <disclaimer.h>
Ed Skinner, Technical Training, Motorola Inc., MicroComputer Division
2900 S Diablo Way, Tempe Az 85282, USA (602)438-3956
Internet: edski@phx.mcd.mot.com,  UUCPnet: noao!asuvax!mcdphx!edski
Re: Catch Source Code Errors - Tricks Wanted
#1006
Author: John Dilley
Date: Thu, 11 Oct 1990 21:32
40 lines
2778 bytes
In article <13785@mcdphx.phx.mcd.mot.com> edski@phx.mcd.mot.com (Ed Skinner) writes:

>	One drawback, of course, is that the source file must be coded in
>a cb(1) format in order to use cb(1) to "find" differences between what
>I mean and what the compiler will understand.  This format may not conform
>with your favorite style, nor that of your employer.  However, I am willing
>to change my habits (and style) when I find something that will help me
>generate better code in less time.

	I find that GNU emacs allows me to generate better code in much
less time than I was able to generate before.  In general, GNU emacs
lets me be more effective overall (generating code is maybe 20% or 30%
of what my job entails over extended periods of time).

	Specifically, to address the issue of having to write code in
cb(1) format -- emacs has c-mode, which is highly extensible so that I
can define what *my* c-mode should look like.  As long as my co-workers
and I can read it easily, my employer should have no problem with it.
Plus, as I enter the code initially an emacs function bound to a key
will adjust (beautify) an arbitrary region of C program text (or C++,
lisp, nroff, Tex, FORTRAN (eww! :-) or straight ASCII text as you see
here).  Basically I can catch that before I even write the file out.

	I could go on for quite a while -- and start an editor war I am
not prepared to wage -- but won't.  My message for you is that you
should not have to change your ways to accomodate the computer ... the
computer should change its ways to accomodate your style.  I think Apple
was the first company to really embrace this philosophy.  Emacs helps
me, personally, to do this.

                          --      jad      --
			      John Dilley
			    Hewlett-Packard
                       Colorado Networks Division
UX-mail:      		     jad@cnd.hp.com
Phone:                       (303) 229-2787
--
This is not an official statement from Hewlett-Packard Corp., and does not
necessarily reflect the official position of HP.  The information above is
provided in good faith but completely without warranty of any kind.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads