Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #9535

Re: identation

From blp@cs.stanford.edu (Ben Pfaff)
Newsgroups comp.lang.c
Subject Re: identation
Date 2011-08-18 10:23 -0700
Message-ID <878vqqocql.fsf@blp.benpfaff.org> (permalink)
References <23c66ecd-e562-4e3d-afb8-4b428995b493@h9g2000vbr.googlegroups.com>

Show all headers | View raw


dmjcunha <dmjcunha@gmail.com> writes:

> Hi. The code below is exactly as it is in the book Algorithmsin c
> third edition. I just would like to know if there was an error of
> identation in the compexch.

There is silly indentation, but there are plenty of other
problems and questionable practices also.  I would not use this
code for anything.

Here are a few problems I noticed quickly.  First, there's no
"#typedef" preprocessor directive.  Evidently "typedef int Item;"
is what was meant:
> #typedef int Item
> #define key(A) (A)
> #define less(A, B) (key(A) < key(B)

The following macro expands its arguments multiple times and
fails to protect itself with do...while(0):
> #define exch(A, B) {Item t = A; A = B; B = t;}

Ditto:
> #define compexch(A, B) if (less(B, A)) exch(A, B)

"M" is a pretty lousy name for a macro:
> #define M 10

'l' is a lousy name for a variable, especially in a function that
also uses the integer '1':
> void quicksort(Item a[], int l, int r)

This indentation style is weird:

>    {int i;
>    if(r - l <= M) return;
>    exch(a[(l + r) / 2], a[r - 1]);

It is very unconventional to indent in the following "stair-step"
way:
>    compexch(a[l], a[r - 1];
>        compexch(a[l], a[r]);
>            compexch(a[r - 1], a[r]);
>    i = partition(a, l + 1, r - 1);
>    quicksort(a, l, i - 1)
>    quicksort(a, i + 1, r);
> }

-- 
int main(void){char p[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.\
 \n",*q="kl BIcNBFr.NKEzjwCIxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+=strchr(p,*q++)-p;if(i>=(int)sizeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

identation dmjcunha <dmjcunha@gmail.com> - 2011-08-18 10:01 -0700
  Re: identation John Gordon <gordon@panix.com> - 2011-08-18 17:09 +0000
  Re: identation blp@cs.stanford.edu (Ben Pfaff) - 2011-08-18 10:23 -0700
    Re: identation gwowen <gwowen@gmail.com> - 2011-08-19 00:07 -0700
      Re: identation James Kuyper <jameskuyper@verizon.net> - 2011-08-19 08:26 -0400
  Re: identation Ike Naar <ike@sverige.freeshell.org> - 2011-08-18 17:44 +0000

csiph-web