Subroutine layout in C

Jeff A. Bowles bowles at eris.berkeley.edu
Sat Jan 7 04:05:32 AEST 1989


>In article <2459 at ssc-vax.UUCP> dmg at ssc-vax.UUCP (David Geary) writes:
>
>  Frank is correct, this is exactly what you want to do.  However, I like
>to do the following:
>
>#define PRIVATE static
>#define PUBLIC 
> ...

I worked for a very short time for a creepy compiler company that had
several hundred thousand lines of this sort of crap.

	PRIVATE  -> static
	PUBLIC	-> ""
	INT16	-> short int
	INT32	-> long int

and so on. By the time these fools were done, they weren't coding
in C, they were coding in their own language - and often it was just
because they liked a particular style that the K&R compiler [proper]
didn't accept.

One person I know used typedef's for every last data type in a fairly
large control system. You would see a declaration like
	THING x;
and not know if you could put "&" in front of it (it might be an array)
or if it was a integral object or what. Data hiding is one thing, but
not if it's incomplete, and not if it serves no purpose.

We've all seen (or heard about) the source to the Bourne shell, in which
Steve Bourne furnished ALGOL-like #defines and wrote the entire shell in
it. (Don't get me wrong, I like Algol W, an older language, more than I
do C - in many contexts.)

But if you're using the C preprocessor, or things like typedefs, to
reformat a program, ask how much you're asking someone to know about
your program before you do it. It's one thing to clarify an often-existing
sequence of code, e.g.
	#define	REGLOOP(i)	for(i = 0; i < REGSZ; ++i)
or to hide an implementation within library routines or header files,
as in the case of the "-ldbm" or "-lmp" libraries, and another to gratituously
add the sort of foolishness the original posting suggests.

Some people use:
	typedef enum {true = 1, false = 0} boolean;
and when you're able to use this single line, and later say "if (true)..."
I'll probably use this - it DOES make things clearer. I believe that ANSI C
will make this sort of thing easier, which is good.


Where is the line? Probably the best way to answer is by asking if the
statement (e.g. "if (true)..." or "REGLOOP(i) { ... }") would make sense
in a fragment.

And it's hard to convince me that most pretty-printing would.

	Jeff Bowles



More information about the Comp.lang.c mailing list