Re: Which code style do you prefer the most?

Liste des GroupesRevenir à cl c  
Sujet : Re: Which code style do you prefer the most?
De : anton.txt (at) *nospam* g{oogle}mail.com (Anton Shepelev)
Groupes : comp.lang.c
Date : 04. Mar 2025, 15:56:02
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20250304175602.c9fe683d678d3a2ed101a4ac@g{oogle}mail.com>
References : 1
User-Agent : Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32)
Ar Rakin:

I've been writing C code for a long time, in different styles, but
always wanted to know which code style most people prefer. This is all
about that question. Which one of the following do you prefer the most?

1. GNU Style
2. Linux Style

I don't like them much. Below is a piece of my code
(previosly shown in this group). It uses tabs for
indentation and spaces for alignment.

-- sort.c --
#include <stdio.h>
#include <limits.h>
#include "sort.h"

/* Partition an array [l..r] around a "pivot" member so that */
/* the elements of the left sub-array do not exceed, and the ones */
/* of the right sub-array are not less than, the pivot. */
static int /* returns the right boundary of the left sub-array */
partition
( void * data, /* pointer to the full array              */
int    l,    /* left  boundary of the sub-array        */
int    r,    /* right boundary of the sub-array, l < r */
  comp_f comp,
swap_f swap,
void * extra
)
{ int p; /* index of the pivot, element */
p = ( l + r ) / 2; /* Chose the middle element as pivot */

while( 1 )
{ /* advance cursors until they stop at a pair of elements */
/* that should be swapped or meet or go past each other.  */
/* The pivot element serves as a sentinel.                */
while( comp( data, l, p, extra ) < 0 ) l += 1;
while( comp( data, r, p, extra ) > 0 ) r -= 1;
if( l >= r ) break;

swap( data, l, r );      /* Swap the pair found         */
     if( l == p ) p = r; /* Update pivot location if it */
else if( r == p ) p = l; /* was changed during the swap */

/* Advance the cursors. If they are adjecent they will cross: */
l += 1; r -= 1;
}
return r;
}

void sort
( void * data,
int    len,
comp_f comp,
swap_f swap,
void * extra
)
{  /* In this algorithm, minimun sufficient stack size is Log(len) */
int sl[sizeof(int) * CHAR_BIT]; /* left  sub-array boundaries on the stack */
int sr[sizeof(int) * CHAR_BIT]; /* right sub-array boundaries nn the stack */

int d;          /* stack depth */
int l, r;       /* left and right boundaries of a sub-array */
int lpos, rpos; /* positions of the left and right new sub-arrays on the stack */
int newr;       /* the right boundary of the new left sub-array */

d     = 1; /* Put the initial sub-array onto the stack */
sl[0] = 0; sr[0] = len - 1;
while( d > 0 )
{ d -= 1; /* Take an element from the stack */
l = sl[d]; r = sr[d];
if( l >= r ) continue; /* Skip a subarray shorter than two */

newr = partition( data, l , r, comp, swap, extra );

/* process the shorter sub-array first to ease the stack: */
lpos = d; rpos = d;
if( newr - l > r - newr - 1 ) rpos += 1;
else                          lpos += 1;

/* Put partiioned sub-arrays onto the stack: */
sl[lpos] = l;        sr[lpos] = newr;
sl[rpos] = newr + 1; sr[rpos] = r;
d += 2;
}
}
-- sort.h --
/* ----------------------- A generic sorting routine ------------------------ */
/* Comparison function:
    > 0 <=> data[i] > data[j]
    < 0 <=> data[i] < data[j]
   == 0 <=> data[i] = data[j] */
typedef int  (*comp_f)( const void * data, int i, int j, void * extra );

/* Exchange ith and jth elements: */
typedef void (*swap_f)( void * data, int i, int j );

void sort
( void * data, /* pointer to data to sort         */
int    len,  /* length of data to sort          */
comp_f comp, /* comparison function             */
swap_f swap, /* swap function                   */
void * extra /* user-supplied parameter to comp */
);
-- test.c --
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "sort.h"

static void print( int * a, int n )
{ int i;
for( i = 0; i < n; i++ )
printf("%i ", a[i] );
printf("\n");
}

static int intcomp( int a, int b )
{ if( a > b ) return  1;
if( a < b ) return -1;
            return  0;
}

static int comp( const void * data, int i, int j, void * extra )
{ return intcomp( ( (int*)data )[i], ( (int*)data )[j] );  }

/* comparison for qsort: */
static int qscomp(const void * a, const void * b)
{ return intcomp( *(int*)a, *(int*)b );  }

static void swap( void * data, int i, int j )
{ int buf;
buf = ( (int*)data )[i];
( (int*)data )[i] = ( (int*)data )[j];
( (int*)data )[j] = buf;
}

#define TESTLEN 500
/* performance test with a random array: */
static void test()
{ int     a[TESTLEN], c[TESTLEN];
int     i, j;
clock_t start, total;

total = 0;
for( i = 0; i < 1000; i++ )
{ for( j = 0; j < TESTLEN; j++ )
{ a[j] = rand() % 5;
c[j] = a[j];
}
start = clock();
/*qsort( a, testlen, sizeof(int), &qscomp );*/
sort( a, TESTLEN, &comp, &swap, NULL );
total += clock() - start;
for( j = 0; j < TESTLEN-1; j++ )
{ if( a[j] > a[j+1] )
{ print( c, TESTLEN );
print( a, TESTLEN );
return;
}
}
}
printf("Time: %f\n", (float)total / CLOCKS_PER_SEC );
}

/* test with a small hard-coded array: */
#define TMLEN 3
static void testman( void )
{ int ta[TMLEN] = {3,2,1};
print( ta, TMLEN );
sort ( ta, TMLEN, &comp, &swap, NULL );
print( ta, TMLEN );
}

int main( int argc, char** argv )
{ /*testman();
return 0;*/

test();
return 0;
}

Date Sujet#  Auteur
25 Feb 25 * Which code style do you prefer the most?272Ar Rakin
25 Feb 25 +* Re: Which code style do you prefer the most?108David LaRue
25 Feb 25 i`* Re: Which code style do you prefer the most?107Ar Rakin
25 Feb 25 i +* Re: Which code style do you prefer the most?104David Brown
25 Feb 25 i i+* Re: Which code style do you prefer the most?102Ar Rakin
25 Feb 25 i ii`* Re: Which code style do you prefer the most?101David Brown
25 Feb 25 i ii +* Re: Which code style do you prefer the most?3Janis Papanagnou
26 Feb 25 i ii i`* Re: Which code style do you prefer the most?2David Brown
26 Feb 25 i ii i `- Re: Which code style do you prefer the most?1Janis Papanagnou
26 Feb 25 i ii `* Re: Which code style do you prefer the most?97Ar Rakin
26 Feb 25 i ii  +* Re: Which code style do you prefer the most?4Janis Papanagnou
27 Feb 25 i ii  i`* Re: Which code style do you prefer the most?3Lawrence D'Oliveiro
27 Feb 25 i ii  i +- Re: Which code style do you prefer the most?1Janis Papanagnou
27 Feb 25 i ii  i `- Re: Which code style do you prefer the most?1Ar Rakin
26 Feb 25 i ii  `* Re: Which code style do you prefer the most?92David Brown
26 Feb 25 i ii   `* Re: Which code style do you prefer the most?91Bradley K. Sherman
26 Feb 25 i ii    +* Re: Which code style do you prefer the most?48David Brown
26 Feb 25 i ii    i+* Re: Which code style do you prefer the most?41Janis Papanagnou
26 Feb 25 i ii    ii`* Re: Which code style do you prefer the most?40David Brown
27 Feb 25 i ii    ii `* Re: Which code style do you prefer the most?39Janis Papanagnou
27 Feb 25 i ii    ii  `* Re: Which code style do you prefer the most?38David Brown
28 Feb 25 i ii    ii   +* Re: Which code style do you prefer the most?25Richard Harnden
28 Feb 25 i ii    ii   i`* Re: Which code style do you prefer the most?24Michael S
28 Feb 25 i ii    ii   i +- Re: Which code style do you prefer the most?1Lawrence D'Oliveiro
2 Mar 25 i ii    ii   i `* Re: Which code style do you prefer the most?22Tim Rentsch
3 Mar 25 i ii    ii   i  +* Re: Which code style do you prefer the most?6Michael S
3 Mar 25 i ii    ii   i  i+* Re: Which code style do you prefer the most?4bart
3 Mar 25 i ii    ii   i  ii+* Re: Which code style do you prefer the most?2Richard Harnden
3 Mar 25 i ii    ii   i  iii`- Re: Which code style do you prefer the most?1bart
4 Mar 25 i ii    ii   i  ii`- Re: Which code style do you prefer the most?1Lawrence D'Oliveiro
3 Mar 25 i ii    ii   i  i`- Re: Which code style do you prefer the most?1Tim Rentsch
3 Mar 25 i ii    ii   i  +- Re: Which code style do you prefer the most?1Tim Rentsch
4 Mar 25 i ii    ii   i  `* Re: Which code style do you prefer the most?14Keith Thompson
4 Mar 25 i ii    ii   i   +* Re: Which code style do you prefer the most?7Lawrence D'Oliveiro
4 Mar 25 i ii    ii   i   i`* Re: Which code style do you prefer the most?6Janis Papanagnou
4 Mar 25 i ii    ii   i   i `* Re: Which code style do you prefer the most?5Lawrence D'Oliveiro
4 Mar 25 i ii    ii   i   i  +- Re: Which code style do you prefer the most?1Keith Thompson
4 Mar 25 i ii    ii   i   i  `* Re: Which code style do you prefer the most?3Lawrence D'Oliveiro
5 Mar 25 i ii    ii   i   i   `* Re: Which code style do you prefer the most?2Janis Papanagnou
5 Mar 25 i ii    ii   i   i    `- Re: Which code style do you prefer the most?1Lawrence D'Oliveiro
21 Mar 25 i ii    ii   i   `* Re: Which code style do you prefer the most?6Tim Rentsch
22 Mar 25 i ii    ii   i    +* Re: Which code style do you prefer the most?2Tim Rentsch
22 Mar 25 i ii    ii   i    i`- Re: Which code style do you prefer the most?1Tim Rentsch
1 Apr 25 i ii    ii   i    `* Re: 80 char lines and holerith cards [Was:Which code style do you prefer the most?]3Jakob Bohm
1 Apr 25 i ii    ii   i     +- Re: 80 char lines and holerith cards [Was:Which code style do you prefer the most?]1Janis Papanagnou
1 Apr 25 i ii    ii   i     `- Re: 80 char lines and holerith cards [Was:Which code style do you prefer the most?]1Janis Papanagnou
28 Feb 25 i ii    ii   `* Re: Which code style do you prefer the most?12Janis Papanagnou
28 Feb 25 i ii    ii    `* Re: Which code style do you prefer the most?11David Brown
28 Feb 25 i ii    ii     +* Re: Which code style do you prefer the most?9Richard Harnden
28 Feb 25 i ii    ii     i+- Re: Which code style do you prefer the most?1David Brown
28 Feb 25 i ii    ii     i`* Re: Which code style do you prefer the most?7Lawrence D'Oliveiro
1 Mar 25 i ii    ii     i `* Re: Which code style do you prefer the most?6Richard Harnden
1 Mar 25 i ii    ii     i  +* Re: Which code style do you prefer the most?4Richard Heathfield
1 Mar 25 i ii    ii     i  i`* Re: Which code style do you prefer the most?3Keith Thompson
1 Mar 25 i ii    ii     i  i +- Re: Which code style do you prefer the most?1Richard Harnden
1 Mar 25 i ii    ii     i  i `- Re: Which code style do you prefer the most?1David Brown
1 Mar 25 i ii    ii     i  `- Re: Which code style do you prefer the most?1Lawrence D'Oliveiro
1 Mar 25 i ii    ii     `- Re: Which code style do you prefer the most?1Janis Papanagnou
26 Feb 25 i ii    i+- Re: Which code style do you prefer the most?1David Brown
27 Feb 25 i ii    i+* Re: Which code style do you prefer the most?2Ar Rakin
27 Feb 25 i ii    ii`- Re: Which code style do you prefer the most?1David Brown
9 Mar 25 i ii    i`* Re: Which code style do you prefer the most?3Tim Rentsch
9 Mar 25 i ii    i `* Re: Which code style do you prefer the most?2Janis Papanagnou
10 Mar 25 i ii    i  `- Re: Which code style do you prefer the most?1Tim Rentsch
27 Feb 25 i ii    `* Re: Which code style do you prefer the most?42Lawrence D'Oliveiro
27 Feb 25 i ii     `* Re: Which code style do you prefer the most?41Janis Papanagnou
27 Feb 25 i ii      `* Re: Which code style do you prefer the most?40Lawrence D'Oliveiro
27 Feb 25 i ii       `* Re: Which code style do you prefer the most?39Janis Papanagnou
27 Feb 25 i ii        `* Re: Which code style do you prefer the most?38Lawrence D'Oliveiro
28 Feb 25 i ii         `* Re: Which code style do you prefer the most?37Janis Papanagnou
28 Feb 25 i ii          +* Re: Which code style do you prefer the most?33Richard Heathfield
28 Feb 25 i ii          i`* Re: Which code style do you prefer the most?32Janis Papanagnou
28 Feb 25 i ii          i `* Re: Which code style do you prefer the most?31Richard Heathfield
28 Feb 25 i ii          i  +- Re: Which code style do you prefer the most?1Janis Papanagnou
28 Feb 25 i ii          i  +* Re: Which code style do you prefer the most?4bart
28 Feb 25 i ii          i  i+* Re: Which code style do you prefer the most?2Michael S
28 Feb 25 i ii          i  ii`- Re: Which code style do you prefer the most?1Lawrence D'Oliveiro
28 Feb 25 i ii          i  i`- Re: Which code style do you prefer the most?1Ar Rakin
28 Feb 25 i ii          i  +- Re: Which code style do you prefer the most?1Chris M. Thomasson
28 Feb 25 i ii          i  +- Re: Which code style do you prefer the most?1Kaz Kylheku
28 Feb 25 i ii          i  `* Re: Which code style do you prefer the most?23Lawrence D'Oliveiro
1 Mar 25 i ii          i   `* Re: Which code style do you prefer the most?22David Brown
1 Mar 25 i ii          i    +* Re: Which code style do you prefer the most?20Janis Papanagnou
1 Mar 25 i ii          i    i`* Re: Which code style do you prefer the most?19Lawrence D'Oliveiro
1 Mar 25 i ii          i    i `* Re: Which code style do you prefer the most?18Janis Papanagnou
2 Mar 25 i ii          i    i  +* Re: Which code style do you prefer the most?12Keith Thompson
2 Mar 25 i ii          i    i  i+* Re: Which code style do you prefer the most?2Lawrence D'Oliveiro
2 Mar 25 i ii          i    i  ii`- Re: Which code style do you prefer the most?1Keith Thompson
2 Mar 25 i ii          i    i  i+- Re: Which code style do you prefer the most?1Tim Rentsch
2 Mar 25 i ii          i    i  i+- Re: Which code style do you prefer the most?1Janis Papanagnou
2 Mar 25 i ii          i    i  i+- Re: Which code style do you prefer the most?1Janis Papanagnou
2 Mar 25 i ii          i    i  i+* Re: Which code style do you prefer the most?3bart
2 Mar 25 i ii          i    i  ii+- Re: Which code style do you prefer the most?1Keith Thompson
2 Mar 25 i ii          i    i  ii`- Re: Which code style do you prefer the most?1Lawrence D'Oliveiro
2 Mar 25 i ii          i    i  i`* Re: Which code style do you prefer the most?3David Brown
2 Mar 25 i ii          i    i  i `* Re: Which code style do you prefer the most?2bart
2 Mar 25 i ii          i    i  i  `- Re: Which code style do you prefer the most?1David Brown
2 Mar 25 i ii          i    i  `* Re: Which code style do you prefer the most?5Janis Papanagnou
2 Mar 25 i ii          i    i   +* [OT] Pascal identifiers [digression] (was Re: Which code style do you prefer the most?)3Janis Papanagnou
2 Mar 25 i ii          i    i   i`* Re: [OT] Pascal identifiers [digression] (was Re: Which code style do you prefer the most?)2Keith Thompson
3 Mar 25 i ii          i    i   i `- Re: [OT] Pascal identifiers [digression] (was Re: Which code style do you prefer the most?)1Lawrence D'Oliveiro
2 Mar 25 i ii          i    i   `- Re: Which code style do you prefer the most?1Lawrence D'Oliveiro
1 Mar 25 i ii          i    `- Re: Which code style do you prefer the most?1Dan Cross
2 Mar 25 i ii          `* Re: Which code style do you prefer the most?3Tim Rentsch
25 Feb 25 i i`- Re: Which code style do you prefer the most?1Janis Papanagnou
25 Feb 25 i +- Re: Which code style do you prefer the most?1Ar Rakin
25 Feb 25 i `- Re: Which code style do you prefer the most?1Janis Papanagnou
25 Feb 25 +* Re: Which code style do you prefer the most?42John McCue
25 Feb 25 +* Re: Which code style do you prefer the most?2Rosario19
25 Feb 25 +- Re: Which code style do you prefer the most?1Janis Papanagnou
25 Feb 25 +* Re: Which code style do you prefer the most?57Lawrence D'Oliveiro
2 Mar 25 +- Re: Which code style do you prefer the most?1Tim Rentsch
4 Mar 25 +* Re: Which code style do you prefer the most?59Anton Shepelev
18 Mar 25 `- Re: Which code style do you prefer the most?1Bonita Montero

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal