more about programming style

Lowell Savage savage at ssc-vax.UUCP
Tue Aug 6 03:48:26 AEST 1985


*** REPLACE THIS LINE WITH YOUR MICRO, PLEASE ***
>From Bob Weiler there was this hint:
> I find a partial solution to the def problem is to use the following
> style of declarations religously.
> 
> #define MYSTRUCT_T	struct mystruct
> struct mystruct {
> 	int		whatever;
> 	MYSTRUCT_T	*next;
> };
> typedef MYSTRUCT_T	mystruct_t, *mystruct_p;
> #define	MYSTRUCTSZ	(sizeof(mystruct_t))
> #define	NULLMYSTRUCT	((mystruct_p)0)
> 
> I would appreciate comments, suggestions, etc. on additional ways to
> make type declarations more readable. But enough already about ++.

Hear! Hear!  Another suggestion that I will add is to use typedefs.  In this
case:

	typedef
	struct mystruct {
		int		whatever;
		mystruct	*next;
	};
	mystruct	*mystruct_p;
	#define		MYSTRUCTSZ	(sizeof(mystruct))

I have always HAD to do this when I was declaring arrays of pointers to
functions, as in:

	typedef
	struct  mystruct {
		int		x;
		mystruct	*nextrv;
	};
	typedef
	mystruct *ret_val;
	typedef
	ret_val	func_type();
	func_type *func_pt;
	func_pt	func_array[10];	/* An array of pointers to functions returning
				   a pointer to a structure mystruct. */

Perhaps some of the steps could be run together in the same declaration, but
it certainly helps when a nested declaration turns into a nested mess of *'s,
()'s, []'s, etc.

				There's more than one way to be savage,

				Lowell Savage

P.S.  I have not checked my declarations very carefully, so they could be
wrong, I just tried to bang this out to get the idea across.



More information about the Comp.lang.c mailing list