comp.lang.c - 25 new messages in 7 topics - digest
comp.lang.c
http://groups.google.com/group/comp.lang.c?hl=en
Today's topics:
* Warning to newbies - 11 messages, 6 authors
http://groups.google.com/group/comp.lang.c/t/9597fd702985dff4?hl=en
* Looking for external program invocations - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c/t/4ab20cd6f143fa06?hl=en
* SMTP Client - 4 messages, 4 authors
http://groups.google.com/group/comp.lang.c/t/fd5e81482c2e8dd1?hl=en
* Motivation of software professionals - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.c/t/21a3fdec4dd53e6a?hl=en
* a question about 1-dimension and 2-dimension array - 4 messages, 2 authors
http://groups.google.com/group/comp.lang.c/t/12a853df84e98d5c?hl=en
* A bit resistant to disruption - 2 messages, 1 author
http://groups.google.com/group/comp.lang.c/t/a5ddb7c1aa07c7e5?hl=en
* calling a singly-linked list - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c/t/163ef25eec8f0a79?hl=en
==============================================================================
TOPIC: Warning to newbies
http://groups.google.com/group/comp.lang.c/t/9597fd702985dff4?hl=en
==============================================================================
== 1 of 11 ==
Date: Tues, Feb 9 2010 2:06 am
From: Nick Keighley
On 9 Feb, 08:57, spinoza1111 <spinoza1...@yahoo.com> wrote:
> On Feb 8, 7:15 pm, Phil Carmody <thefatphil_demun...@yahoo.co.uk>
> wrote:
> > Seebs <usenet-nos...@seebs.net> writes:
> > > On 2010-02-07,spinoza1111<spinoza1...@yahoo.com> wrote:
> > >> char * replace(char * strMaster,
> > >> char * strTarget,
> > >> char * strReplacement)
> > >> {
>
> > > So far, this looks fine.
>
> > Lack of consts makes it look amateurish.
I don't agree. Use of const slightly improves the code, but I probably
wouldn't reject code at a walkthru for lack of const (I might comment
though).
<snip>
> Pray why do we need constants?
"const" not "constants". "const" is a C keyword that indicates to the
compiler that the function isn't going to change the value. It labels
the parameters as strictly input only (it also the function using the
parameters as temporary variables- which should please you!). It has
semantics (in this case) of something like Ada's "in" parameters.
"const" is a bit like "assert" its much more powerful than you at
first appreciate.
> They are, almost by definition, one
> more point of failure.
how so? How are const parameters more prone to failure?
> I lack consts because I don't cover up
> incompetence by using "buffers" (the use of which term is always a
> sign of incompetence).
I've no idea what you are talking about
> I didn't need constants because I used a linked
> list, for I learned long ago that hard-coded limits are trouble.
what?
--
the unemployed programmer had a problem. "I know", said the
programmer, "I'll just learn perl." the unemployed programmer
now had two problems.
Eric Naggum (comp.lang.lisp)
== 2 of 11 ==
Date: Tues, Feb 9 2010 2:25 am
From: "io_x"
"spinoza1111" <spinoza1111@yahoo.com> ha scritto nel messaggio
news:bfb05ba9-6fd2-4a34-86c2-29d3c72bd58a@e33g2000prn.googlegroups.com...
On Feb 7, 10:48 pm, i...@localhost.claranet.nl (Ike Naar) wrote:
> In article
> <d206650c-a2ee-42ba-9aed-fc51ac577...@t34g2000prm.googlegroups.com>,
>
> spinoza1111 <spinoza1...@yahoo.com> wrote:
> >Hopefully a final version.
>
> Your hope is in vain.
> replace("abab","ba","ba") = "aba" ?
No, I fixed that. Here is a version just for you, with this test
added.
-----------------
do you read me? someone read me?
this below is better
// ---------------------------------------------------------------
// Statement-format test macro
//
//
#define TESTER(resultPtr, master, target, replacement, expected) \
{ \
printf("Expect \"%s\":\n\"%s\"\n\n", \
(expected), \
resultPtr = replace((master), \
(target), \
(replacement))); \
free(resultPtr); \
}
because align the string expected to the result
and is easier to ceck
test1
Expect "a miracle":
"a miracle"
Expect "a miracle error":
"a miracle error"
Expect "a miracle":
"a miracle"
Expect "a miracle":
"a miracle"
Expect "a miracle":
"a miracle"
Expect "snirpKamunkle":
"snirpKamunkle"
Expect " snirpKamunkle":
" snirpKamunkle"
Expect " snirpKamunkle":
" snirpKamunkle"
Expect " snirpKamunkle a Miracle":
" snirpKamunkle a Miracle"
Expect "a miracled":
"a miracled"
Expect "a stupid errod":
"a stupid errod"
Expect "a smiracle":
"a smiracle"
Expect "a miraclemiracle":
"a miraclemiracle"
Expect "a miracle stupiderror":
"a miracle stupiderror"
Expect "aaaaaaaaaa":
"aaaaaaaaaa"
Expect "In the halls of R'yleh great Cthulu lies dreaming":
"In the halls of R'yleh great Cthulu lies dreaming"
Expect "CthuluCthuluCthuluCthuluCthuluCthulu":
"CthuluCthuluCthuluCthuluCthuluCthulu"
Expect "boatna":
"boatna"
Expect " a ++Hey+s":
" a ++Hey+s"
Expect "basbasf":
"basbasf"
Expect "abab":
"abab"
== 3 of 11 ==
Date: Tues, Feb 9 2010 2:33 am
From: spinoza1111
On Feb 9, 1:35 am, Seebs <usenet-nos...@seebs.net> wrote:
> On 2010-02-08, Phil Carmody <thefatphil_demun...@yahoo.co.uk> wrote:
>
> > Seebs <usenet-nos...@seebs.net> writes:
> >> On 2010-02-07,spinoza1111<spinoza1...@yahoo.com> wrote:
> >>> char * replace(char * strMaster,
> >>> char * strTarget,
> >>> char * strReplacement)
> >>> {
> >> So far, this looks fine.
> > Lack of consts makes it look amateurish.
>
> While I chose to use consts in mine, I am quite sympathetic to avoiding
> const, because I did it for years. That said, I do agree that it would
> be improved by the use of const qualifiers.
My mistake, you meant read-only const qualifiers. My apologies for
this misunderstanding. I will add the const qualifiers to the next
version. Do you want to be credited?
No, I am not talking to you, Peter, although you will be credited if
you contribute anything useful.
>
> -s
> --
> Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nos...@seebs.nethttp://www.seebs.net/log/<-- lawsuits, religion, and funny pictureshttp://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
== 4 of 11 ==
Date: Tues, Feb 9 2010 2:40 am
From: spinoza1111
On Feb 9, 7:32 am, Phil Carmody <thefatphil_demun...@yahoo.co.uk>
wrote:
> blm...@myrealbox.com <blm...@myrealbox.com> writes:
> > In article <0cd7a7f4-f9ce-47f7-8437-b4d6d1bbb...@s36g2000prf.googlegroups.com>,
> >spinoza1111 <spinoza1...@yahoo.com> wrote:
> >> Moore's law won't help us much with NP complete solutions.
>
> > Or NP-complete problems. (Terminology quibble? Maybe.)
>
> Not at all. The bilgemaster encounters what he considers to be
> academic-sounding terms, and then repeats them hoping that he'll
> be treated as someone even vaguely erudite. Unfortunately, he
> uses the terms in completely hatstand contexts, and thus fails
> dramatically. Tragic, and best ignored.
You're mistaking the verbal flexibility of someone who's actually
studied NP complete issues (graduate level class in algorithms, grade
== A) with misuse of "terminology", where unqualified little clerks
have to watch their mouths and use of "terminology" lest their brutal
slave-masters kill them for using the wrong "ears of corn", of
shibboleths.
Fuck you very much, buddy. And stop making games of people's names.
Fourteen year olds do that.
[The use of four letter words is normally less malicious than
deliberately trashing reputations. There's a world of difference
between "fuck you", which means in many contexts "get laid, it might
help you be less of a jerk" and trashing a patronym. "Fuck you" in
isolation can later change to friendship, as in the Army, whereas use
of Rahm Emanuel's "retard" with or without "fucking" means "this
person doesn't belong in the conversation"; and, Jean Francois Lyotard
defines the essence of real terrorism as exclusion from conversation.
Of course, hardly any of you served in the military, and this is
possibly why you act like jerks. The military teaches many lessons,
some good, some bad.]
>
> Phil
> --
> Any true emperor never needs to wear clothes. -- Devany on r.a.s.f1
== 5 of 11 ==
Date: Tues, Feb 9 2010 2:42 am
From: spinoza1111
On Feb 9, 6:25 pm, "io_x" <a...@b.c.invalid> wrote:
> "spinoza1111" <spinoza1...@yahoo.com> ha scritto nel messaggionews:bfb05ba9-6fd2-4a34-86c2-29d3c72bd58a@e33g2000prn.googlegroups.com...
> On Feb 7, 10:48 pm, i...@localhost.claranet.nl (Ike Naar) wrote:
>
> > In article
> > <d206650c-a2ee-42ba-9aed-fc51ac577...@t34g2000prm.googlegroups.com>,
>
> >spinoza1111<spinoza1...@yahoo.com> wrote:
> > >Hopefully a final version.
>
> > Your hope is in vain.
> > replace("abab","ba","ba") = "aba" ?
>
> No, I fixed that. Here is a version just for you, with this test
> added.
>
> -----------------
>
> do you read me? someone read me?
> this below is better
> // ---------------------------------------------------------------
> // Statement-format test macro
> //
> //
> #define TESTER(resultPtr, master, target, replacement, expected) \
> { \
> printf("Expect \"%s\":\n\"%s\"\n\n", \
> (expected), \
> resultPtr = replace((master), \
> (target), \
> (replacement))); \
> free(resultPtr); \
>
> }
>
> because align the string expected to the result
> and is easier to ceck
>
> test1
> Expect "a miracle":
> "a miracle"
>
> Expect "a miracle error":
> "a miracle error"
>
> Expect "a miracle":
> "a miracle"
>
> Expect "a miracle":
> "a miracle"
>
> Expect "a miracle":
> "a miracle"
>
> Expect "snirpKamunkle":
> "snirpKamunkle"
>
> Expect " snirpKamunkle":
> " snirpKamunkle"
>
> Expect " snirpKamunkle":
> " snirpKamunkle"
>
> Expect " snirpKamunkle a Miracle":
> " snirpKamunkle a Miracle"
>
> Expect "a miracled":
> "a miracled"
>
> Expect "a stupid errod":
> "a stupid errod"
>
> Expect "a smiracle":
> "a smiracle"
>
> Expect "a miraclemiracle":
> "a miraclemiracle"
>
> Expect "a miracle stupiderror":
> "a miracle stupiderror"
>
> Expect "aaaaaaaaaa":
> "aaaaaaaaaa"
>
> Expect "In the halls of R'yleh great Cthulu lies dreaming":
> "In the halls of R'yleh great Cthulu lies dreaming"
>
> Expect "CthuluCthuluCthuluCthuluCthuluCthulu":
> "CthuluCthuluCthuluCthuluCthuluCthulu"
>
> Expect "boatna":
> "boatna"
>
> Expect " a ++Hey+s":
> " a ++Hey+s"
>
> Expect "basbasf":
> "basbasf"
>
> Expect "abab":
> "abab"
Good idea! Thanks. Shall I credit you in the Change Record?
== 6 of 11 ==
Date: Tues, Feb 9 2010 3:32 am
From: "io_x"
"io_x" <a@b.c.invalid> ha scritto nel messaggio
news:4b712e1a$0$1130$4fafbaef@reader3.news.tin.it...
>
> "James" <no@spam.invalid> ha scritto nel messaggio
> news:hkna39$9us$1@speranza.aioe.org...
>> "Seebs" <usenet-nospam@seebs.net> wrote in message
>> news:slrnhmtte2.lfb.usenet-nospam@guild.seebs.net...
>> [...]
> What about this?
I found some bugs
replace("string ", "", "append")
has to return "string append"
and not forever loop
hope this post in not so much long and someone see it
#include <stdio.h>
#include <stdlib.h>
#define P printf
char* __stdcall SostituisciPercS(char* origin, char* whatSost, char* sost);
// origin has to came from malloc memory
int Print(char** origin, char* whatSost, char* sost)
{char *p=SostituisciPercS(*origin, whatSost, sost);
int i;
if(p==0) return 0;
P("Origin=%s|WhatS=%s|Sost=%s\n", *origin, whatSost, sost);
P("Result=%s\n", p);
free(*origin); *origin=p;
return 1;
}
int test(void)
{int r;
char *src, c;
src=realloc(0, 1024);
if(src==0) return 0;
for(r=0; ; ++r)
{c="XYXYX--XYXYXY--XYXYXY"[r];
// c="XY123XY456"[r];
src[r]=c;
if(c==0) break;
}
r = Print(&src, "", "append");
if(r==0) {free(src); return 0;}
r = Print(&src, "XY", "AB");
if(r==0) {free(src); return 0;}
r = Print(&src, "--", "<-->");
if(r==0) {free(src); return 0;}
r = Print(&src, "--", "<-->");
if(r==0) {free(src); return 0;}
r = Print(&src, "<<", "|");
if(r==0) {free(src);return 0;}
r = Print(&src, ">>", "|");
if(r==0) {free(src); return 0;}
r = Print(&src, "ABABAB", "1234");
if(r==0) {free(src); return 0;}
r = Print(&src, "ABABX", "ABCDEFG");
if(r==0) {free(src); return 0;}
r = Print(&src, "-", "");
if(r==0) {free(src); return 0;}
r = Print(&src, "||", "<<XXX>>");
if(r==0) {free(src); return 0;}
r = Print(&src, "<X", "-");
if(r==0) {free(src); return 0;}
r = Print(&src, ">X", "--->");
if(r==0) {free(src); return 0;}
r = Print(&src, "X>", "X--->");
if(r==0) {free(src); return 0;}
r = Print(&src, "1234", "!");
if(r==0) {free(src); return 0;}
r = Print(&src, "<-XX--->>!", "!");
if(r==0) {free(src); return 0;}
r = Print(&src, "ABCD", "Hello");
if(r==0) {free(src); return 0;}
r = Print(&src, "EFG", " World");
if(r==0) {free(src); return 0;}
r = Print(&src, "!@#", "123456789");
if(r==0) {free(src); return 0;}
r = Print(&src, "!!", "!");
if(r==0) {free(src); return 0;}
r = Print(&src, "Hello", "Goodbye");
if(r==0) {free(src); return 0;}
r = Print(&src, "!", "! We are going to miss you!");
if(r==0) {free(src); return 0;}
r = Print(&src, "are", "");
if(r==0) {free(src); return 0;}
free(src);
return 0;
}
// ---------------------------------------------------------------
// Statement-format test macro
//
//
#define TESTER(resultPtr, master, target, replacement, expected) \
{ \
printf("Expect \"%s\":\n \"%s\"\n\n", \
(expected), \
resultPtr = SostituisciPercS((master), \
(target), \
(replacement))); \
free(resultPtr); \
}
// ---------------------------------------------------------------
// Main procedure
//
//
int test1(void)
{
char *ptrResult;
printf("\ntest1\n");
TESTER(ptrResult,
"a stupid error",
"stupid error",
"miracle",
"a miracle")
TESTER(ptrResult,
"a stupid error",
"stupid",
"miracle",
"a miracle error")
TESTER(ptrResult,
"the stupid error",
"the stupid error",
"a miracle",
"a miracle")
TESTER(ptrResult,
"the miracle",
"the",
"a",
"a miracle")
TESTER(ptrResult,
"a miraclsnirpKamunkle",
"snirpKamunkle",
"e",
"a miracle")
TESTER(ptrResult,
"a miraclesnirpKamunkle",
"a miracle",
"",
"snirpKamunkle")
TESTER(ptrResult,
" a miraclesnirpKamunkle",
"a miracle",
"",
" snirpKamunkle")
TESTER(ptrResult,
" a miraclesnirpKamunklea miraclea miracle",
"a miracle",
"",
" snirpKamunkle")
TESTER(ptrResult,
"a miracle a miraclesnirpKamunkle a Miraclea miraclea miracle",
"a miracle",
"",
" snirpKamunkle a Miracle")
TESTER(ptrResult,
"a stupid errord",
"stupid error",
"miracle",
"a miracled")
TESTER(ptrResult,
"a stupid errod",
"stupid error",
"miracle",
"a stupid errod")
TESTER(ptrResult,
"a sstupid error",
"stupid error",
"miracle",
"a smiracle")
TESTER(ptrResult,
"a stupid errorstupid error",
"stupid error",
"miracle",
"a miraclemiracle")
TESTER(ptrResult,
"a stupid error stupiderror",
"stupid error",
"miracle",
"a miracle stupiderror")
TESTER(ptrResult,
"bbbbbbbbbb",
"b",
"a",
"aaaaaaaaaa")
TESTER(ptrResult,
"In the halls of R'yleh great %s lies dreaming",
"%s",
"Cthulu",
"In the halls of R'yleh great Cthulu lies dreaming")
TESTER(ptrResult,
"%s%s%s%s%s%s",
"%s",
"Cthulu",
"CthuluCthuluCthuluCthuluCthuluCthulu")
TESTER(ptrResult,
"banana",
"ana",
"oat",
"boatna")
TESTER(ptrResult,
" a stupid errorstupid errorHeystupid errors",
"stupid error",
"+",
" a ++Hey+s")
TESTER(ptrResult,
"foo barfoo barf",
"foo bar",
"bas",
"basbasf")
TESTER(ptrResult,
"abab",
"ba",
"ba",
"abab")
printf("\n\nTesting complete: check output carefully!\n\n");
return 0;
}
int main(void)
{test();
test1();
return 0;
}
-------------------
section _DATA use32 public class=DATA
global SostituisciPercS
extern _realloc
extern _free
section _BSS use32 public class=BSS
section _TEXT use32 public class=CODE
; 0k,4j,8i,12b,16ra, 20P_fmt, 24P_WhatSost 28P_Sost + 64
; 84 88 92
; 0inString, 4sizeResult, 8NowArg
SostituisciPercS:
push ebx
push esi
push edi
push ebp
sub esp, 64
mov esi, dword[esp+ 84]
cmp dword[esp+ 88], 0
je .e0
cmp dword[esp+ 92], 0
je .e0
cmp esi, 0
je .e0 ; k=current arg, j array
mov edi, 0
mov dword[esp+ 0], 0
mov dword[esp+ 4], 0
mov dword[esp+ 8], 0 ; ^8==led string sub ==\0==""
mov ebx, 0
jmp short .0 ; 0led_isstring b is index [len]
.e: push edi
call _free
.e0: xor eax, eax
stc
jmp .z
.0: cmp ebx, dword[esp+ 4]
jb .1
mov ecx, ebx
add ecx, 32
push ecx
push ecx
push edi
call _realloc
add esp, 8
pop ecx
cmp eax, 0
je .e
mov edi, eax
mov dword[esp+ 4], ecx
.1: cmp dword[esp], 1
jne .3
xor eax, eax
mov al, [ebp]
cmp eax, 0
jne .2
mov dword[esp+ 0], 0
cmp dword[esp+ 8], 1
je .7
jmp short .0
.2: mov byte[edi+ebx], al
inc ebp
inc ebx
jmp short .0
.3: mov ebp, dword[esp+ 88]
xor eax, eax
mov ecx, esi ; cerca di vedere se le stringhe sono uguali
.4: mov al, [ebp]
cmp eax, 0
je .5
cmp al, [ecx]
jne .7
inc ecx
inc ebp
jmp short .4
.5: cmp ecx, esi
jne .5a ; stringa nulla da sostituire
cmp al, [ecx]
jne .7 ; se B*c==0 allora sostituisci, altrimenti
continua
mov dword[esp+ 8], 1
.5a: mov dword[esp+ 0], 1
mov esi, ecx
mov ebp, dword[esp+ 92]
jmp .0
.ee: jmp .e
.7: mov al, [esi]
mov byte[edi+ebx], al
inc esi
inc ebx
cmp eax, 0
je .8
jmp .0
.8: push ebx
push edi
call _realloc
add esp, 8
cmp eax, 0
je .ee
clc
.z:
lea esp, [esp+64]
pop ebp
pop edi
pop esi
pop ebx
ret 12
---------------------
Origin=XYXYX--XYXYXY--XYXYXY|WhatS=|Sost=append
Result=XYXYX--XYXYXY--XYXYXYappend
Origin=XYXYX--XYXYXY--XYXYXYappend|WhatS=XY|Sost=AB
Result=ABABX--ABABAB--ABABABappend
Origin=ABABX--ABABAB--ABABABappend|WhatS=--|Sost=<-->
Result=ABABX<-->ABABAB<-->ABABABappend
Origin=ABABX<-->ABABAB<-->ABABABappend|WhatS=--|Sost=<-->
Result=ABABX<<-->>ABABAB<<-->>ABABABappend
Origin=ABABX<<-->>ABABAB<<-->>ABABABappend|WhatS=<<|Sost=|
Result=ABABX|-->>ABABAB|-->>ABABABappend
Origin=ABABX|-->>ABABAB|-->>ABABABappend|WhatS=>>|Sost=|
Result=ABABX|--|ABABAB|--|ABABABappend
Origin=ABABX|--|ABABAB|--|ABABABappend|WhatS=ABABAB|Sost=1234
Result=ABABX|--|1234|--|1234append
Origin=ABABX|--|1234|--|1234append|WhatS=ABABX|Sost=ABCDEFG
Result=ABCDEFG|--|1234|--|1234append
Origin=ABCDEFG|--|1234|--|1234append|WhatS=-|Sost=
Result=ABCDEFG||1234||1234append
Origin=ABCDEFG||1234||1234append|WhatS=|||Sost=<<XXX>>
Result=ABCDEFG<<XXX>>1234<<XXX>>1234append
Origin=ABCDEFG<<XXX>>1234<<XXX>>1234append|WhatS=<X|Sost=-
Result=ABCDEFG<-XX>>1234<-XX>>1234append
Origin=ABCDEFG<-XX>>1234<-XX>>1234append|WhatS=>X|Sost=--->
Result=ABCDEFG<-XX>>1234<-XX>>1234append
Origin=ABCDEFG<-XX>>1234<-XX>>1234append|WhatS=X>|Sost=X--->
Result=ABCDEFG<-XX--->>1234<-XX--->>1234append
Origin=ABCDEFG<-XX--->>1234<-XX--->>1234append|WhatS=1234|Sost=!
Result=ABCDEFG<-XX--->>!<-XX--->>!append
Origin=ABCDEFG<-XX--->>!<-XX--->>!append|WhatS=<-XX--->>!|Sost=!
Result=ABCDEFG!!append
Origin=ABCDEFG!!append|WhatS=ABCD|Sost=Hello
Result=HelloEFG!!append
Origin=HelloEFG!!append|WhatS=EFG|Sost= World
Result=Hello World!!append
Origin=Hello World!!append|WhatS=!@#|Sost=123456789
Result=Hello World!!append
Origin=Hello World!!append|WhatS=!!|Sost=!
Result=Hello World!append
Origin=Hello World!append|WhatS=Hello|Sost=Goodbye
Result=Goodbye World!append
Origin=Goodbye World!append|WhatS=!|Sost=! We are going to miss you!
Result=Goodbye World! We are going to miss you!append
Origin=Goodbye World! We are going to miss you!append|WhatS=are|Sost=
Result=Goodbye World! We going to miss you!append
test1
Expect "a miracle":
"a miracle"
Expect "a miracle error":
"a miracle error"
Expect "a miracle":
"a miracle"
Expect "a miracle":
"a miracle"
Expect "a miracle":
"a miracle"
Expect "snirpKamunkle":
"snirpKamunkle"
Expect " snirpKamunkle":
" snirpKamunkle"
Expect " snirpKamunkle":
" snirpKamunkle"
Expect " snirpKamunkle a Miracle":
" snirpKamunkle a Miracle"
Expect "a miracled":
"a miracled"
Expect "a stupid errod":
"a stupid errod"
Expect "a smiracle":
"a smiracle"
Expect "a miraclemiracle":
"a miraclemiracle"
Expect "a miracle stupiderror":
"a miracle stupiderror"
Expect "aaaaaaaaaa":
"aaaaaaaaaa"
Expect "In the halls of R'yleh great Cthulu lies dreaming":
"In the halls of R'yleh great Cthulu lies dreaming"
Expect "CthuluCthuluCthuluCthuluCthuluCthulu":
"CthuluCthuluCthuluCthuluCthuluCthulu"
Expect "boatna":
"boatna"
Expect " a ++Hey+s":
" a ++Hey+s"
Expect "basbasf":
"basbasf"
Expect "abab":
"abab"
Testing complete: check output carefully!
== 7 of 11 ==
Date: Tues, Feb 9 2010 4:12 am
From: ike@localhost.claranet.nl (Ike Naar)
In article <4b7145cc$0$1137$4fafbaef@reader1.news.tin.it>,
io_x <a@b.c.invalid> wrote:
>I found some bugs
>replace("string ", "", "append")
>has to return "string append"
>and not forever loop
It is not obvious that replace("string ", "", "append") should
return "string append". According to the specification, it
should replace all occurrences of the empty pattern "" in "string "
with the substitute "append".
You seem to claim that the empty pattern only occurs once,
at the end of "string ", but it would be equally valid to say that
an empty pattern occurs, for instance, between the 'r' and the 'i'
of "string ", so the result "strappending " would be okay, too.
One might even argue that "string " contains the empty pattern infinitely
often, and in that case it's only natural that replacing them all will
take forever ;-)
== 8 of 11 ==
Date: Tues, Feb 9 2010 4:33 am
From: Ben Bacarisse
"io_x" <a@b.c.invalid> writes:
<snip>
> do you read me? someone read me?
> this below is better
> // ---------------------------------------------------------------
> // Statement-format test macro
> //
> //
> #define TESTER(resultPtr, master, target, replacement, expected) \
> { \
> printf("Expect \"%s\":\n\"%s\"\n\n", \
> (expected), \
> resultPtr = replace((master), \
> (target), \
> (replacement))); \
> free(resultPtr); \
> }
>
> because align the string expected to the result
> and is easier to ceck
Surely it would be better still to have the program check that the
strings are the same?
int fail(const char *s, const char *t, const char *r, const char *e)
{
const char *result = replace(s, t, r);
return result && strcmp(result, e) == 0 ? (free(result), 0) : 1;
}
and then the number of failed tests can simply be accumulated by
adding the results with the sum being zero to indicate success. Of
course, a print can be added as well for visual inspection.
<snip>
--
Ben.
== 9 of 11 ==
Date: Tues, Feb 9 2010 5:03 am
From: spinoza1111
On Feb 9, 7:32 pm, "io_x" <a...@b.c.invalid> wrote:
> "io_x" <a...@b.c.invalid> ha scritto nel messaggionews:4b712e1a$0$1130$4fafbaef@reader3.news.tin.it...
>
>
>
> > "James" <n...@spam.invalid> ha scritto nel messaggio
> >news:hkna39$9us$1@speranza.aioe.org...
> >> "Seebs" <usenet-nos...@seebs.net> wrote in message
> >>news:slrnhmtte2.lfb.usenet-nospam@guild.seebs.net...
> >> [...]
> > What about this?
>
> I found some bugs
> replace("string ", "", "append")
> has to return "string append"
> and not forever loop
Not in my code. If the target is null, I cause an error. Admittedly
the error handling is as Peter Seebach says, crude, so on my to-do
list is a less-crude error handler.
>
> hope this post in not so much long and someone see it
>
> #include <stdio.h>
> #include <stdlib.h>
> #define P printf
>
> char* __stdcall SostituisciPercS(char* origin, char* whatSost, char* sost);
>
> // origin has to came from malloc memory
> int Print(char** origin, char* whatSost, char* sost)
> {char *p=SostituisciPercS(*origin, whatSost, sost);
> int i;
> if(p==0) return 0;
> P("Origin=%s|WhatS=%s|Sost=%s\n", *origin, whatSost, sost);
> P("Result=%s\n", p);
> free(*origin); *origin=p;
> return 1;
>
> }
>
> int test(void)
> {int r;
> char *src, c;
>
> src=realloc(0, 1024);
> if(src==0) return 0;
> for(r=0; ; ++r)
> {c="XYXYX--XYXYXY--XYXYXY"[r];
> // c="XY123XY456"[r];
> src[r]=c;
> if(c==0) break;
> }
>
> r = Print(&src, "", "append");
> if(r==0) {free(src); return 0;}
>
> r = Print(&src, "XY", "AB");
> if(r==0) {free(src); return 0;}
> r = Print(&src, "--", "<-->");
> if(r==0) {free(src); return 0;}
> r = Print(&src, "--", "<-->");
> if(r==0) {free(src); return 0;}
> r = Print(&src, "<<", "|");
> if(r==0) {free(src);return 0;}
> r = Print(&src, ">>", "|");
> if(r==0) {free(src); return 0;}
> r = Print(&src, "ABABAB", "1234");
> if(r==0) {free(src); return 0;}
> r = Print(&src, "ABABX", "ABCDEFG");
> if(r==0) {free(src); return 0;}
> r = Print(&src, "-", "");
> if(r==0) {free(src); return 0;}
> r = Print(&src, "||", "<<XXX>>");
> if(r==0) {free(src); return 0;}
> r = Print(&src, "<X", "-");
> if(r==0) {free(src); return 0;}
> r = Print(&src, ">X", "--->");
> if(r==0) {free(src); return 0;}
> r = Print(&src, "X>", "X--->");
> if(r==0) {free(src); return 0;}
> r = Print(&src, "1234", "!");
> if(r==0) {free(src); return 0;}
> r = Print(&src, "<-XX--->>!", "!");
> if(r==0) {free(src); return 0;}
> r = Print(&src, "ABCD", "Hello");
> if(r==0) {free(src); return 0;}
> r = Print(&src, "EFG", " World");
> if(r==0) {free(src); return 0;}
> r = Print(&src, "!@#", "123456789");
> if(r==0) {free(src); return 0;}
> r = Print(&src, "!!", "!");
> if(r==0) {free(src); return 0;}
> r = Print(&src, "Hello", "Goodbye");
> if(r==0) {free(src); return 0;}
> r = Print(&src, "!", "! We are going to miss you!");
> if(r==0) {free(src); return 0;}
>
> r = Print(&src, "are", "");
> if(r==0) {free(src); return 0;}
>
> free(src);
> return 0;
>
> }
>
> // ---------------------------------------------------------------
> // Statement-format test macro
> //
> //
> #define TESTER(resultPtr, master, target, replacement, expected) \
> { \
> printf("Expect \"%s\":\n \"%s\"\n\n", \
> (expected), \
> resultPtr = SostituisciPercS((master), \
> (target), \
> (replacement))); \
> free(resultPtr); \
>
> }
>
> // ---------------------------------------------------------------
> // Main procedure
> //
> //
> int test1(void)
> {
> char *ptrResult;
> printf("\ntest1\n");
> TESTER(ptrResult,
> "a stupid error",
> "stupid error",
> "miracle",
> "a miracle")
> TESTER(ptrResult,
> "a stupid error",
> "stupid",
> "miracle",
> "a miracle error")
> TESTER(ptrResult,
> "the stupid error",
> "the stupid error",
> "a miracle",
> "a miracle")
> TESTER(ptrResult,
> "the miracle",
> "the",
> "a",
> "a miracle")
> TESTER(ptrResult,
> "a miraclsnirpKamunkle",
> "snirpKamunkle",
> "e",
> "a miracle")
> TESTER(ptrResult,
> "a miraclesnirpKamunkle",
> "a miracle",
> "",
> "snirpKamunkle")
> TESTER(ptrResult,
> " a miraclesnirpKamunkle",
> "a miracle",
> "",
> " snirpKamunkle")
> TESTER(ptrResult,
> " a miraclesnirpKamunklea miraclea miracle",
> "a miracle",
> "",
> " snirpKamunkle")
> TESTER(ptrResult,
> "a miracle a miraclesnirpKamunkle a Miraclea miraclea miracle",
> "a miracle",
> "",
> " snirpKamunkle a Miracle")
> TESTER(ptrResult,
> "a stupid errord",
> "stupid error",
> "miracle",
> "a miracled")
> TESTER(ptrResult,
> "a stupid errod",
> "stupid error",
> "miracle",
> "a stupid errod")
> TESTER(ptrResult,
> "a sstupid error",
> "stupid error",
> "miracle",
> "a smiracle")
> TESTER(ptrResult,
> "a stupid errorstupid error",
> "stupid error",
> "miracle",
> "a miraclemiracle")
> TESTER(ptrResult,
> "a stupid error stupiderror",
> "stupid error",
> "miracle",
> "a miracle stupiderror")
> TESTER(ptrResult,
> "bbbbbbbbbb",
> "b",
> "a",
> "aaaaaaaaaa")
> TESTER(ptrResult,
> "In the halls of R'yleh great %s lies dreaming",
> "%s",
> "Cthulu",
> "In the halls of R'yleh great Cthulu lies dreaming")
> TESTER(ptrResult,
> "%s%s%s%s%s%s",
> "%s",
> "Cthulu",
> "CthuluCthuluCthuluCthuluCthuluCthulu")
> TESTER(ptrResult,
> "banana",
> "ana",
> "oat",
> "boatna")
> TESTER(ptrResult,
> " a stupid errorstupid errorHeystupid errors",
> "stupid error",
> "+",
> " a ++Hey+s")
> TESTER(ptrResult,
> "foo barfoo barf",
> "foo bar",
> "bas",
> "basbasf")
> TESTER(ptrResult,
> "abab",
> "ba",
> "ba",
> "abab")
> printf("\n\nTesting complete: check output carefully!\n\n");
> return 0;
>
> }
>
> int main(void)
> {test();
> test1();
> return 0;
>
> }
>
> -------------------
> section _DATA use32 public class=DATA
>
> global SostituisciPercS
> extern _realloc
> extern _free
>
> section _BSS use32 public class=BSS
> section _TEXT use32 public class=CODE
>
> ; 0k,4j,8i,12b,16ra, 20P_fmt, 24P_WhatSost 28P_Sost + 64
> ; 84 88 92
> ; 0inString, 4sizeResult, 8NowArg
> SostituisciPercS:
> push ebx
> push esi
> push edi
> push ebp
> sub esp, 64
> mov esi, dword[esp+ 84]
> cmp dword[esp+ 88], 0
> je .e0
> cmp dword[esp+ 92], 0
> je .e0
> cmp esi, 0
> je .e0 ; k=current arg, j array
> mov edi, 0
> mov dword[esp+ 0], 0
> mov dword[esp+ 4], 0
> mov dword[esp+ 8], 0 ; ^8==led string sub ==\0==""
> mov ebx, 0
> jmp short .0 ; 0led_isstring b is index [len]
> .e: push edi
> call _free
> .e0: xor eax, eax
> stc
> jmp .z
> .0: cmp ebx, dword[esp+ 4]
> jb .1
> mov ecx, ebx
> add ecx, 32
> push ecx
> push ecx
> push edi
> call _realloc
> add esp, 8
> pop ecx
> cmp eax, 0
> je .e
> mov edi, eax
> mov dword[esp+ 4], ecx
> .1: cmp dword[esp], 1
> jne .3
> xor eax, eax
> mov al, [ebp]
> cmp eax, 0
> jne .2
> mov dword[esp+ 0], 0
> cmp dword[esp+ 8], 1
> je .7
> jmp short .0
> .2: mov byte[edi+ebx], al
> inc ebp
> inc ebx
> jmp short .0
> .3: mov ebp, dword[esp+ 88]
> xor eax, eax
> mov ecx, esi ; cerca di vedere se le stringhe sono uguali
> .4: mov al, [ebp]
> cmp eax, 0
> je .5
> cmp al, [ecx]
> jne .7
> inc ecx
> inc ebp
> jmp short .4
> .5: cmp ecx, esi
> jne .5a ; stringa nulla da sostituire
> cmp al, [ecx]
> jne .7 ; se B*c==0 allora sostituisci, altrimenti
> continua
> mov dword[esp+ 8], 1
> .5a: mov dword[esp+ 0], 1
> mov esi, ecx
> mov ebp, dword[esp+ 92]
> jmp .0
> .ee: jmp .e
> .7: mov al, [esi]
> mov byte[edi+ebx], al
> inc esi
> inc ebx
> cmp eax, 0
> je .8
> jmp .0
> .8: push ebx
> push edi
> call _realloc
> add esp, 8
> cmp eax, 0
> je .ee
> clc
> .z:
> lea esp, [esp+64]
> pop ebp
> pop edi
> pop esi
> pop ebx
> ret 12
> ---------------------
> Origin=XYXYX--XYXYXY--XYXYXY|WhatS=|Sost=append
> Result=XYXYX--XYXYXY--XYXYXYappend
> Origin=XYXYX--XYXYXY--XYXYXYappend|WhatS=XY|Sost=AB
> Result=ABABX--ABABAB--ABABABappend
> Origin=ABABX--ABABAB--ABABABappend|WhatS=--|Sost=<-->
> Result=ABABX<-->ABABAB<-->ABABABappend
> Origin=ABABX<-->ABABAB<-->ABABABappend|WhatS=--|Sost=<-->
> Result=ABABX<<-->>ABABAB<<-->>ABABABappend
> Origin=ABABX<<-->>ABABAB<<-->>ABABABappend|WhatS=<<|Sost=|
> Result=ABABX|-->>ABABAB|-->>ABABABappend
> Origin=ABABX|-->>ABABAB|-->>ABABABappend|WhatS=>>|Sost=|
> Result=ABABX|--|ABABAB|--|ABABABappend
> Origin=ABABX|--|ABABAB|--|ABABABappend|WhatS=ABABAB|Sost=1234
> Result=ABABX|--|1234|--|1234append
> Origin=ABABX|--|1234|--|1234append|WhatS=ABABX|Sost=ABCDEFG...
>
> read more »
== 10 of 11 ==
Date: Tues, Feb 9 2010 5:06 am
From: spinoza1111
On Feb 9, 8:12 pm, i...@localhost.claranet.nl (Ike Naar) wrote:
> In article <4b7145cc$0$1137$4fafb...@reader1.news.tin.it>,
>
> io_x <a...@b.c.invalid> wrote:
> >I found some bugs
> >replace("string ", "", "append")
> >has to return "string append"
> >and not forever loop
>
> It is not obvious that replace("string ", "", "append") should
> return "string append". According to the specification, it
> should replace all occurrences of the empty pattern "" in "string "
> with the substitute "append".
>
> You seem to claim that the empty pattern only occurs once,
> at the end of "string ", but it would be equally valid to say that
> an empty pattern occurs, for instance, between the 'r' and the 'i'
> of "string ", so the result "strappending " would be okay, too.
>
> One might even argue that "string " contains the empty pattern infinitely
> often, and in that case it's only natural that replacing them all will
> take forever ;-)
I just crap out with a deliberate planned abort() (which I shall
refine per Seebach: his participation is welcome insofar as he learns
manners thereby). This is because as you say there is no meaning to a
null target.
There are other theoretical issues such as left to right versus right
to left and whether ana occurs once or twice in banana which shall be
addressed, hopefully.
== 11 of 11 ==
Date: Tues, Feb 9 2010 5:18 am
From: Walter Banks
spinoza1111 wrote:
> I just crap out with a deliberate planned abort()
>
> There are other theoretical issues such as left to right versus right
> to left and whether ana occurs once or twice in banana which shall be
> addressed, hopefully.
I seem to have missed the design and test spec for this exercise.
w..
==============================================================================
TOPIC: Looking for external program invocations
http://groups.google.com/group/comp.lang.c/t/4ab20cd6f143fa06?hl=en
==============================================================================
== 1 of 1 ==
Date: Tues, Feb 9 2010 2:28 am
From: Nobody
On Mon, 08 Feb 2010 09:08:02 +0000, Mark Hobley wrote:
>> system(), exec() and friends, fork(), popen(), perhaps ptrace()..
>
> Thanks Michael.
>
> Just to be clear fork() only calls a copy of the same process doesn't it? So
> it cannot be used to launch arbitary commands?
Correct. "executing" a command typically involves fork() + exec(), but
it's the exec() that causes a specific program to be executed.
> I just looked a ptrace().. that is a funny one. It appears to be able to
> peek and poke at memory addresses of other processes.
Yes. ptrace() is the foundation for any kind of debugger. It allows one
process to monitor and control another. It's also the foundation for
various "sandbox" mechanisms.
> Is there any unrelated vulnerabilities relating to this? (again for future
> reference).
You can only ptrace() a process which you own and which is unprivileged
(exec()ing a setuid/setgid program causes a process to become privileged;
conversely, a process which is created as root but which then setuid()s to
a user account still remains privileged).
It's only a vulnerability if you're trying to impose restrictions above
and beyond the normal Unix account-based permission model.
E.g. if you have a privileged process which performs services on behalf of
an unprivileged process, you can't choose to trust a specific process; you
have to trust the account overall, as the user can control the "trusted"
process via ptrace() (but then they can also intercept library calls via
e.g. $LD_PRELOAD).
==============================================================================
TOPIC: SMTP Client
http://groups.google.com/group/comp.lang.c/t/fd5e81482c2e8dd1?hl=en
==============================================================================
== 1 of 4 ==
Date: Tues, Feb 9 2010 2:29 am
From: richard@cogsci.ed.ac.uk (Richard Tobin)
In article <d08c0ea2-83a5-48ab-8c19-ac9e7c9adf52@21g2000yqj.googlegroups.com>,
J <seaworthyjeremy@gmail.com> wrote:
>Please explain how to authenticate the session
See http://tools.ietf.org/rfc/rfc4954.txt
-- Richard
--
Please remember to mention me / in tapes you leave behind.
== 2 of 4 ==
Date: Tues, Feb 9 2010 2:41 am
From: Luuk
Op 9-2-2010 10:27, Nick Keighley schreef:
> On 9 Feb, 02:07, J <seaworthyjer...@gmail.com> wrote:
>> I am starting a new project to create a SMTP Client for Windows; I am
>> using the winsock2 library. When I use the following commands I get an
>> error (550):
>>
>> 220 ns1.zanmo.com ESMTP Exim 4.69 Mon, 08 Feb 2010 17:58:41 -0800
>> HELO world
>> 250 ns1.zanmo.com Hello 60.sub-75-229-11.myvzw.com [75.229.11.60]
>> MAIL FROM: t...@test.com
>> 250 OK
>> RCPT TO: t...@gmail.com
>> 550 authentication required
>> QUIT
>> 221 ns1.zanmo.com closing connection
>>
>> Please explain how to authenticate the session, and how do I
>> Programmatically MX Lookup also using MX record?
>
> try a better newsgroup. Maybe a microsoft one
microsoft does not do,
this suggegtion comes as close as redirecting someone who askes about C
to 'Borland', because they write (or wrote?) c-compilers...
--
Luuk
== 3 of 4 ==
Date: Tues, Feb 9 2010 2:55 am
From: Nobody
On Mon, 08 Feb 2010 18:07:26 -0800, J wrote:
> I am starting a new project to create a SMTP Client for Windows; I am
> using the winsock2 library. When I use the following commands I get an
> error (550):
>
> 220 ns1.zanmo.com ESMTP Exim 4.69 Mon, 08 Feb 2010 17:58:41 -0800
> HELO world
> 250 ns1.zanmo.com Hello 60.sub-75-229-11.myvzw.com [75.229.11.60]
> MAIL FROM: test@test.com
> 250 OK
> RCPT TO: test@gmail.com
> 550 authentication required
> QUIT
> 221 ns1.zanmo.com closing connection
>
> Please explain how to authenticate the session,
http://tools.ietf.org/html/rfc4954
More generally:
http://en.wikipedia.org/wiki/SMTP#Related_Requests_For_Comments
> and how do I
> Programmatically MX Lookup also using MX record?
Dunno, but DnsQuery() looks promising. If you want a better answer, ask on
a Windows group.
== 4 of 4 ==
Date: Tues, Feb 9 2010 4:00 am
From: Nick Keighley
On 9 Feb, 10:41, Luuk <l...@invalid.lan> wrote:
> Op 9-2-2010 10:27, Nick Keighley schreef:
> > On 9 Feb, 02:07, J <seaworthyjer...@gmail.com> wrote:
> >> I am starting a new project to create a SMTP Client for Windows; I am
> >> using the winsock2 library. When I use the following commands I get an
> >> error (550):
>
> >> 220 ns1.zanmo.com ESMTP Exim 4.69 Mon, 08 Feb 2010 17:58:41 -0800
> >> HELO world
> >> 250 ns1.zanmo.com Hello 60.sub-75-229-11.myvzw.com [75.229.11.60]
> >> MAIL FROM: t...@test.com
> >> 250 OK
> >> RCPT TO: t...@gmail.com
> >> 550 authentication required
> >> QUIT
> >> 221 ns1.zanmo.com closing connection
>
> >> Please explain how to authenticate the session, and how do I
> >> Programmatically MX Lookup also using MX record?
>
> > try a better newsgroup. Maybe a microsoft one
>
> microsoft does not do,
>
> this suggegtion comes as close as redirecting someone who askes about C
> to 'Borland', because they write (or wrote?) c-compilers...
<shrug> he said he was developing a for windows so I thought a windows
might be some use. I must admit I didn't understand his question.
==============================================================================
TOPIC: Motivation of software professionals
http://groups.google.com/group/comp.lang.c/t/21a3fdec4dd53e6a?hl=en
==============================================================================
== 1 of 2 ==
Date: Tues, Feb 9 2010 2:44 am
From: debra h
On Feb 6, 12:39 pm, Roedy Green <see_webs...@mindprod.com.invalid>
wrote:
> On Fri, 5 Feb 2010 04:23:41 -0800 (PST), Richard Cornford
> <Rich...@litotes.demon.co.uk> wrote, quoted or indirectly quoted
> someone who said :
>
>
>
> >Strange question; the most efficient motivator of professionals is
> >money, and money is very popular.
>
> That may be a motivator for taking a job, but I suspect is fairly far
> down the list for leaving a job.
>
> Leaving motivations might include:
>
> personality conflict
> boredom
> too much pressure
>
> Personally, the opportunity to do something I had never done before
> was always the top priority. Employers usually want people who have
> extensive specific experience.
>
> In hiring, my main interest was loyalty. Employees don't get really
> useful until after the first year. I don't expect them to hit the
> ground running. I anticipate investing considerable effort in training
> them. I looked for reasons why they would likely want to stay.
> --
> Roedy Green Canadian Mind Productshttp://mindprod.com
>
> You can't have great software without a great team, and most software teams behave like dysfunctional families.
> ~ Jim McCarthy
Insofar as competent and professional engineering societies set real
standards for qualifications and conduct to be able to use the title
"Engineer", and insofar as the vast majority of software developers
have
nothing like this at all, I see no problem here.
== 2 of 2 ==
Date: Tues, Feb 9 2010 5:23 am
From: Mike Duffy
Roedy Green <see_website@mindprod.com.invalid> wrote in
news:4d5qm59hu2crjdppqr6gun9f5k6mmqvhg1@4ax.com:
> Leaving motivations might include:
>
> personality conflict
> boredom
> too much pressure
- Working hours
- Lack of access to training
- Lack of privacy (email snooping, sharing a desk with others.)
And don't forget work-related health problems or an unhealthy work
environment that management refuses to address. (Harassement, A/C
ventilation, lack of ergonomic furniture, employee security etc.)
Death is always the most compelling reason for not continuing to work.
==============================================================================
TOPIC: a question about 1-dimension and 2-dimension array
http://groups.google.com/group/comp.lang.c/t/12a853df84e98d5c?hl=en
==============================================================================
== 1 of 4 ==
Date: Tues, Feb 9 2010 4:42 am
From: Dimilar Zhu
I have 10000 numbers. Now i need to choose a kind of data structure to save them.
of 1-dimension and 2-dimension array, which is faster? does it depend
on factors such as degree of order, correlation, operations?
== 2 of 4 ==
Date: Tues, Feb 9 2010 3:56 am
From: Luuk
Op 9-2-2010 13:42, Dimilar Zhu schreef:
> I have 10000 numbers. Now i need to choose a kind of data structure to save them.
> of 1-dimension and 2-dimension array, which is faster? does it depend
> on factors such as degree of order, correlation, operations?
if yu write a threaded application, than the number of threads will make
the speed.
so if you have a dual-core processor, take a 2-dimensional array
;-)
--
Luuk
== 3 of 4 ==
Date: Tues, Feb 9 2010 4:02 am
From: Luuk
Op 9-2-2010 13:42, Dimilar Zhu schreef:
> ....., which is faster? ......
btw, why do you care about speed,
you are living in the FUTURE!
--
Luuk
== 4 of 4 ==
Date: Tues, Feb 9 2010 5:30 am
From: dimilar
Luuk <luuk@invalid.lan> writes:
> Op 9-2-2010 13:42, Dimilar Zhu schreef:
>> ....., which is faster? ......
>
> btw, why do you care about speed,
> you are living in the FUTURE!
just a question, yesterday my boss asked me. he is a doctor, and do not know
much about detail of computer language. but at that time i do not know how
to answer it. so I said, "it depends....blablabla".
later a guy told me that there were distinct performance result for large
scale of data if taking account of memory cache and memory access.
for 2-dimension array, it is necessary to do much multiplication to obtain the
index of element. compared to the addition of 1-dimension array, it consumes
more time.
but I did not do any experiment to verify it.
==============================================================================
TOPIC: A bit resistant to disruption
http://groups.google.com/group/comp.lang.c/t/a5ddb7c1aa07c7e5?hl=en
==============================================================================
== 1 of 2 ==
Date: Tues, Feb 9 2010 3:50 am
From: Francois Grieu
Seebs wrote:
> On 2010-02-09, Francois Grieu <fgrieu@gmail.com> wrote:
>>> // Read a designated EEPROM cell; always returns 0 or 1.
>>> extern int eRead(int j);
>>> // Erase a designated EEPROM cell.
>>> // After undisrupted eErase, eRead returns 0 until eProgram is invoked.
>>> extern void eErase(int j);
>>> // Program a designated *ERASED* EEPROM cell.
>>> // After undisrupted eProgram, eRead returns 1 until eErase is invoked.
>>> // Programming a cell that is not erased cause undefined behavior.
>>> extern void eProgram(int j);
>
> [re: my first attempt]
>> This one is incorrect. Assume a disruption where I inserted [A]; now
>> cell 2 is uncertain. Assume cell 2 is read as 1 during the next bToggle,
>> and a disruption occurs at [B]; now cells 0 and 2 are uncertain, and
>> bRead can return 0 (if cells 2 and 0 are read as 0) or 1 (if cell 2 is
>> read as 0 and cell 0 is read as 1).
>>
>> Hint: there's nothing to prevent bRead from invoking eErase or/and eProgram.
>
> I get it! The risk here is that if eRead() returns unreliable results,
> future queries of the same bit may not yield the same results, resulting
> in inconsistent flow through the program logic; in particular, attempts
> might be made to modify things based on spurious data.
Yes. See below ;-)
> So.
>
> int
> bSureOf(int j) {
> if (eRead(j)) {
> eErase(j);
> eProgram(j);
> return 1;
> } else {
> eErase(j);
> return 0;
> }
> }
>
> int
> bRead(void) {
> if (bSureOf(2)) {
> return eRead(1);
> } else {
> return eRead(0);
> }
> }
>
> void
> bToggle(void) {
> int t;
> if (bSureOf(2)) {
> t = eRead(1);
> eErase(0);
> if (t)
> eProgram(0); // [B]
> eErase(2);
> }
> t = eRead(0);
> eErase(1);
> if (t)
> eProgram(1);
> eProgram(2);
> eErase(0); // [A]
> if (!t)
> eProgram(0);
> eErase(2);
> }
Assume that on a bToggle(), a disruption occurs where I added [A], tus
with cell 2 fully programmed. Assume the next disruption occurs in the
next bToggle(), which will thus take the branch where I added [B].
Assume this disruption is during the eProgram(0) on the left of [B],
leaving cell 0 undefined, and cell 2 fully programmed.
An undisrupted bRead now returns eRead(0), which is unspecified, and
leaves cell 2 fully programmed. Thus two undisrupted bRead() without a
bToggle() in between can return different results. Bust.
[snip]
Francois Grieu
== 2 of 2 ==
Date: Tues, Feb 9 2010 4:12 am
From: Francois Grieu
[I messed up my earlier reply, sorry; let me try again]
Seebs wrote :
> On 2010-02-09, Francois Grieu <fgrieu@gmail.com> wrote:
>>> // Read a designated EEPROM cell; always returns 0 or 1.
>>> extern int eRead(int j);
>>> // Erase a designated EEPROM cell.
>>> // After undisrupted eErase, eRead returns 0 until eProgram is invoked.
>>> extern void eErase(int j);
>>> // Program a designated *ERASED* EEPROM cell.
>>> // After undisrupted eProgram, eRead returns 1 until eErase is invoked.
>>> // Programming a cell that is not erased cause undefined behavior.
>>> extern void eProgram(int j);
>
> [re: my first attempt]
>> This one is incorrect. Assume a disruption where I inserted [A]; now
>> cell 2 is uncertain. Assume cell 2 is read as 1 during the next bToggle,
>> and a disruption occurs at [B]; now cells 0 and 2 are uncertain, and
>> bRead can return 0 (if cells 2 and 0 are read as 0) or 1 (if cell 2 is
>> read as 0 and cell 0 is read as 1).
>>
>> Hint: there's nothing to prevent bRead from invoking eErase or/and eProgram.
>
> I get it! The risk here is that if eRead() returns unreliable results,
> future queries of the same bit may not yield the same results, resulting
> in inconsistent flow through the program logic; in particular, attempts
> might be made to modify things based on spurious data.
Yes. See below ;-)
> So.
>
> int
> bSureOf(int j) {
> if (eRead(j)) {
> eErase(j); // [C]
> eProgram(j);
> return 1;
> } else {
> eErase(j);
> return 0;
> }
> }
>
> int
> bRead(void) {
> if (bSureOf(2)) {
> return eRead(1);
> } else {
> return eRead(0);
> }
> }
>
> void
> bToggle(void) {
> int t;
> if (bSureOf(2)) {
> t = eRead(1);
> eErase(0);
> if (t)
> eProgram(0); // [B]
> eErase(2);
> }
> t = eRead(0);
> eErase(1);
> if (t)
> eProgram(1);
> eProgram(2);
> eErase(0); // [A]
> if (!t)
> eProgram(0);
> eErase(2);
> }
>
We get a fist disruption at [A]. Cell 2 is fully programmed. Next
disruption is when bToggle() is doing eProgram(0) on the left of [B].
Cell 0 is undefined. We then do bRead() which is disrupted during
bSureOf(2), after eErase(2) at [C]. Now cell 2 is erased, and an
undisrupted bRead() returns eRead(0), which is unspecified. Two
undisrupted bRead() without a bToggle() in betwwen can thus return
different values. Bust.
[snip]
Francois Grieu
==============================================================================
TOPIC: calling a singly-linked list
http://groups.google.com/group/comp.lang.c/t/163ef25eec8f0a79?hl=en
==============================================================================
== 1 of 1 ==
Date: Tues, Feb 9 2010 4:27 am
From: "bartc"
"frank" <frank@example.invalid> wrote in message
news:7tceuqFausU1@mid.individual.net...
> node.next = list;
++count;
> Again with input as above, can we cheat in main somehow to determine how
> many integers are in this array?
If you really want to cheat, just declare an int count, at file scope, and
increment it as above.
Then main() becomes:
int main(void)
{
int i;
int *numbers,*p;
count=0;
numbers = read_numbers(0);
/* do stuff with numbers[] I guess */
p=numbers;
for (i=0; i<count; ++i) printf("%d\n",*p++);
return 0;
}
This is bad programming however. Better to add an extra parameter to
read_numbers(), a location to return a count. Or just add an extra zero
value to the end of the array (since zero can't be an input value).
--
Bartc
==============================================================================
You received this message because you are subscribed to the Google Groups "comp.lang.c"
group.
To post to this group, visit http://groups.google.com/group/comp.lang.c?hl=en
To unsubscribe from this group, send email to comp.lang.c+unsubscribe@googlegroups.com
To change the way you get mail from this group, visit:
http://groups.google.com/group/comp.lang.c/subscribe?hl=en
To report abuse, send email explaining the problem to abuse@googlegroups.com
==============================================================================
Google Groups: http://groups.google.com/?hl=en
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home