C Indentation Survey Results

Chris Torek chris at umcp-cs.UUCP
Wed May 8 09:29:04 AEST 1985


> From: warner at orca.UUCP (Ken Warner)

> Below is an actual example of real C code. It's in K&R orthodox bracing
> style.

>	switch (key) {
>	case BACK:
>	fprintf(stoout,"BACK\n");

Why isn't this "fprintf" indented another tabstop?

>		if (device->s.stroke.current_editpos > 1) {
>			device->s.stroke.current_editpos--;
>			for (device->s.stroke.editptr =
>			 &(device->s.stroke.header), 
>			 i = 1;
>			 device->s.stroke.editptr->next->next,
>			 i < device->s.stroke.current_editpos;
>			 device->s.stroke.editptr =
>			 device->s.stroke.editptr->next, 
>			 i++ ) {
>				;
>			 }
>		} else {

I don't quite understand.  Is the reference to
device->s.stroke.editptr->next->next in the test part of the for loop
supposed to cause a memory fault if there is no next?  The value is
tossed because of the comma operator.

This code would probably be more readable and faster if you had back
pointers.  Even without them, how about using

	register struct /*whatever_device->s.stroke_is*/ *s;
	.
	.
	.
	switch (key) {
	case BACK:
		fprintf(stoout, "BACK\n");
		s = &device->s.stroke;
		if (s->current_editpos > 1) {
			s->current_editpos--;
			/* s->editptr = s->editptr->prev; */
			s->editptr = &s->header;
			for (i = 1; i < s->current_editpos; i++)
				s->editptr = s->editptr->next;
		} else {

> Is it easier to read because of it?

Yes.

(By the way, why > 1 rather than >= 1?  Can't you untype the first key?
The code would appear to work for editpos==1...)
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 4251)
UUCP:	{seismo,allegra,brl-bmd}!umcp-cs!chris
CSNet:	chris at umcp-cs		ARPA:	chris at maryland



More information about the Comp.lang.c mailing list