From: io_x on

"io_x" <a(a)b.c.invalid> ha scritto nel messaggio
news:4b8e25c6$0$824$4fafbaef(a)reader5.news.tin.it...
>
> "Poster Matt" <postermatt(a)no_spam_for_me.org> ha scritto nel messaggio
> news:ujehn.44277$Ym4.21796(a)text.news.virginmedia.com...
>> Hi,
>>
>> I've a few questions concerning style when programming C on UNIX systems. I
>> don't want to look like an amateur. :)
>
> all code here came from the poster "Peter Nilsson" from
> news:f6245590-e586-4cb0-88f8-37afcebe15d4(a)s25g2000prd.googlegroups.com
>
> that can not be seen in my monitor editor,
> here too in the editor of the news
> is better than my amatorish stile
> #include <string.h>
> #include <stdlib.h>
>
> char* replace2_search(size_t n, char* s,
> char* p, size_t pz,
> char* q, size_t qz )
> {char *f, *r;
> size_t z;
> if(pz==0 || !(f = strstr(s, p)))
> {z= strlen(s); r= (char*) malloc(n+z+1);
> if(r)
> strcpy(r+n, s);
> }
> else
> {z= f-s;
> r= replace2_search(n+z+qz, f+pz, p, pz, q, qz);
> if(r){memcpy(r+n, s, z);
> memcpy(r+n+z, q, qz);
> }
> }
> return r;
> }


char* replace2_search(size_t n, char* s, char* p, size_t pz,
char* q, size_t qz )
{char *f, *r;
size_t z;
if(pz==0 || !(f = strstr(s, p)))
{z= strlen(s);
if(r= (char*) malloc(n+z+1))
strcpy(r+n, s); }
else {z= f-s;
if(r=replace2_search(n+z+qz, f+pz, p, pz, q, qz))
{memcpy(r+n, s, z);
memcpy(r+n+z, q, qz);} }
return r;
}

> char* replace2(char *s, char *p, char *q)
> {if(s==0||p==0||q==0) return 0;
> return replace2_search(0, s, p, strlen(p), q, strlen(q));
> }
>
> that can be seen in one aye shot
>
>
>
>




From: Nick Keighley on
On 5 Mar, 22:29, la...(a)ludens.elte.hu (Ersek, Laszlo) wrote:

> For example, Pascal has := for assignment and = for equality (IIRC :)). Even
> in C, I started out with "x == 7".  I was occasionally bitten by
> "if (x = 7)" typos.  

I even went though the occaisional
x == 3;

somehow AutoPilot (the not very bright bit of the brain that handles
the routine stuff like getting to work and writing code) had come up
with the rule "in C we double up '=' symbols"


From: Nick Keighley on
On 5 Mar, 17:31, Tim Streater <timstrea...(a)waitrose.com> wrote:
> On 05/03/2010 16:04, Richard Heathfield wrote:


> > This is C we're discussing, not English. It is folly to pretend that the
> > rules of English apply to C.
>
> But Richard, you have to read the code in order to interpret it mentally
> and decide whether it's correct or not, or how to amend it. I gave up on
> Forth, Lisp, and regexps for just this reason.

I guess by "read" you mean subvocalise. I can read Lisp without
difficulty and regexps rather slowly. Never seriously tried Forth.

I'm pretty sure I subvocalise because I've acquired some odd
pronounciations for words that had been in my reading vocabulary
longer than my spoken vocabulary. I think the subroutine that assigns
sounds to unfamiliar words is fast but stupid.


From: Nick Keighley on
On 5 Mar, 18:26, Seebs <usenet-nos...(a)seebs.net> wrote:
> On 2010-03-05, Richard Heathfield <r...(a)see.sig.invalid> wrote:
>
> > This is C we're discussing, not English. It is folly to pretend that the
> > rules of English apply to C.
>
> Actually, I'm not exactly talking about English.  I'm talking about the
> underlying cognitive structures English (and every other language) maps to.

ah! A disciple of Chompsky.I didn't know it had been proven beyond
doubt that such a Deep Structure existed

> So far as I know, regardless of language, humans distinguish between the
> topic and the comment (thanks to another poster for providing the
> terminology).
>
> > Ignoring. Probably a minor thinko on his part, no big deal.
>
> Not a big deal, but oddly, somewhat related -- it's the kind of mistake that
> shows up as a side-effect of added complexity.  If you add enough parentheses
> to an expression, people will start mismatching them or putting them in the
> wrong places because they can't track them automatically anymore, or because
> the automatic tracking fails.

to write lisp you pretty well have to have support from your editor. I
seem to nest stuff deeper than most people- maybe this is something
computer programmers tend to do but lisp easily busts my internal
stack.

> For me, swapping the "natural" order of a comparison (I expect the "topic"
> to be first) is one extra layer, similar to an indirection, extra set of
> parentheses, or whatever.  I don't know how common that is, but I'm pretty
> sure it's not going to change in the forseeable future.

I'll suffer the pain of an extra translation stage if I think it buys
me much. In this case I'd rather have the test the "right" way round.
From: Rainer Weikusat on
pete <pfiland(a)mindspring.com> writes:

[...]

> To count down through an array with N elements, I use
>
> size_t i = N;
>
> while (i-- != 0) {
> array[i];
> }

And you excuse for writing confusing code which requests that the
machine does useless things is that software to work around you has
already been developed, right?

First  |  Prev  |  Next  |  Last
Pages: 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
Prev: integer
Next: shared memory question