Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #111691 > unrolled thread
| Started by | "Rick C. Hodgin" <rick.c.hodgin@gmail.com> |
|---|---|
| First post | 2017-06-07 06:16 -0700 |
| Last post | 2017-06-07 08:53 -0700 |
| Articles | 20 on this page of 122 — 18 participants |
Back to article view | Back to comp.lang.c
memscan() function or equivalent "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-07 06:16 -0700
Re: memscan() function or equivalent GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-07 15:47 +0200
Re: memscan() function or equivalent "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-07 07:15 -0700
Re: memscan() function or equivalent scott@slp53.sl.home (Scott Lurndal) - 2017-06-07 14:34 +0000
Re: memscan() function or equivalent "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-07 07:42 -0700
Re: memscan() function or equivalent scott@slp53.sl.home (Scott Lurndal) - 2017-06-07 14:45 +0000
Re: memscan() function or equivalent "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-07 08:07 -0700
Re: memscan() function or equivalent jameskuyper@verizon.net - 2017-06-07 09:14 -0700
Re: memscan() function or equivalent "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-07 09:33 -0700
Re: memscan() function or equivalent GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-07 16:48 +0200
Re: memscan() function or equivalent "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-07 08:31 -0700
Re: memscan() function or equivalent GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-07 17:37 +0200
Re: memscan() function or equivalent "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-07 08:47 -0700
Re: memscan() function or equivalent GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-07 18:02 +0200
Re: memscan() function or equivalent "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-07 09:09 -0700
Re: memscan() function or equivalent GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-07 18:34 +0200
Re: memscan() function or equivalent "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-07 09:54 -0700
Re: memscan() function or equivalent GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-07 19:01 +0200
Re: memscan() function or equivalent "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-07 10:17 -0700
Re: memscan() function or equivalent GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-07 19:53 +0200
Re: memscan() function or equivalent asetofsymbols@gmail.com - 2017-06-07 22:15 -0700
Re: memscan() function or equivalent asetofsymbols@gmail.com - 2017-06-07 22:26 -0700
Re: memscan() function or equivalent asetofsymbols@gmail.com - 2017-06-07 22:56 -0700
Re: memscan() function or equivalent asetofsymbols@gmail.com - 2017-06-07 23:03 -0700
Re: memscan() function or equivalent scott@slp53.sl.home (Scott Lurndal) - 2017-06-07 16:10 +0000
Re: memscan() function or equivalent "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-07 09:30 -0700
Re: memscan() function or equivalent Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-06-07 16:50 +0100
Re: memscan() function or equivalent "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-07 08:58 -0700
Re: memscan() function or equivalent "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-07 09:03 -0700
Re: memscan() function or equivalent "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-07 09:07 -0700
Re: memscan() function or equivalent bartc <bc@freeuk.com> - 2017-06-07 17:30 +0100
Re: memscan() function or equivalent "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-07 09:36 -0700
Re: memscan() function or equivalent bartc <bc@freeuk.com> - 2017-06-07 17:48 +0100
Re: memscan() function or equivalent "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-07 09:57 -0700
Re: memscan() function or equivalent Ike Naar <ike@iceland.freeshell.org> - 2017-06-12 05:54 +0000
Re: memscan() function or equivalent Keith Thompson <kst-u@mib.org> - 2017-06-07 09:48 -0700
Re: memscan() function or equivalent Gareth Owen <gwowen@gmail.com> - 2017-06-07 20:55 +0100
Re: memscan() function or equivalent bartc <bc@freeuk.com> - 2017-06-07 22:13 +0100
Re: memscan() function or equivalent Keith Thompson <kst-u@mib.org> - 2017-06-07 16:02 -0700
Re: memscan() function or equivalent bartc <bc@freeuk.com> - 2017-06-08 01:26 +0100
Re: memscan() function or equivalent Ian Collins <ian-news@hotmail.com> - 2017-06-08 13:00 +1200
Re: memscan() function or equivalent bartc <bc@freeuk.com> - 2017-06-08 09:48 +0100
Re: memscan() function or equivalent "Patrick.Schluter" <Patrick.Schluter@free.fr> - 2017-06-10 08:52 +0200
Re: memscan() function or equivalent supercat@casperkitty.com - 2017-06-07 10:00 -0700
Re: memscan() function or equivalent "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-07 10:13 -0700
Re: memscan() function or equivalent supercat@casperkitty.com - 2017-06-07 11:19 -0700
Re: memscan() function or equivalent "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-07 11:27 -0700
Re: memscan() function or equivalent Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-06-07 21:18 +0100
Re: memscan() function or equivalent GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-07 18:18 +0200
Re: memscan() function or equivalent "Patrick.Schluter" <Patrick.Schluter@free.fr> - 2017-06-07 21:15 +0200
Re: memscan() function or equivalent GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-07 21:16 +0200
Re: memscan() function or equivalent "Patrick.Schluter" <Patrick.Schluter@free.fr> - 2017-06-10 09:08 +0200
Re: memscan() function or equivalent GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-10 09:56 +0200
Re: memscan() function or equivalent "Patrick.Schluter" <Patrick.Schluter@free.fr> - 2017-06-10 17:14 +0200
Re: memscan() function or equivalent GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-10 17:38 +0200
Re: memscan() function or equivalent David Kleinecke <dkleinecke@gmail.com> - 2017-06-10 11:52 -0700
Re: memscan() function or equivalent bartc <bc@freeuk.com> - 2017-06-10 20:03 +0100
Re: memscan() function or equivalent Keith Thompson <kst-u@mib.org> - 2017-06-10 13:32 -0700
Re: memscan() function or equivalent GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-10 23:40 +0200
Re: memscan() function or equivalent Anton Shepelev <anton.txt@gmail.com> - 2017-06-11 00:53 +0300
Re: memscan() function or equivalent Anton Shepelev <anton.txt@gmail.com> - 2017-06-11 01:11 +0300
Re: memscan() function or equivalent Ian Collins <ian-news@hotmail.com> - 2017-06-11 10:26 +1200
Re: memscan() function or equivalent GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-11 00:32 +0200
Re: memscan() function or equivalent "Patrick.Schluter" <Patrick.Schluter@free.fr> - 2017-06-11 10:05 +0200
Re: memscan() function or equivalent GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-11 10:06 +0200
Re: memscan() function or equivalent Keith Thompson <kst-u@mib.org> - 2017-06-11 13:19 -0700
Re: memscan() function or equivalent Anton Shepelev <anton.txt@gmail.com> - 2017-06-11 02:17 +0300
Re: memscan() function or equivalent supercat@casperkitty.com - 2017-06-10 15:21 -0700
Re: memscan() function or equivalent GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-11 00:19 +0200
Re: memscan() function or equivalent Anton Shepelev <anton.txt@gmail.com> - 2017-06-11 02:15 +0300
Re: memscan() function or equivalent "Patrick.Schluter" <Patrick.Schluter@free.fr> - 2017-06-11 10:36 +0200
Re: memscan() function or equivalent GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-11 10:46 +0200
Re: memscan() function or equivalent asetofsymbols@gmail.com - 2017-06-10 22:25 -0700
Re: memscan() function or equivalent "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-10 15:13 -0700
Re: memscan() function or equivalent bartc <bc@freeuk.com> - 2017-06-10 23:21 +0100
Re: memscan() function or equivalent GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-11 00:28 +0200
Re: memscan() function or equivalent bartc <bc@freeuk.com> - 2017-06-11 10:56 +0100
Re: memscan() function or equivalent GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-11 13:27 +0200
Re: memscan() function or equivalent bartc <bc@freeuk.com> - 2017-06-11 13:19 +0100
Re: memscan() function or equivalent Ike Naar <ike@iceland.freeshell.org> - 2017-06-11 18:36 +0000
Re: memscan() function or equivalent bartc <bc@freeuk.com> - 2017-06-11 20:22 +0100
Re: memscan() function or equivalent Ike Naar <ike@iceland.freeshell.org> - 2017-06-12 06:09 +0000
Re: memscan() function or equivalent bartc <bc@freeuk.com> - 2017-06-12 10:38 +0100
Re: memscan() function or equivalent asetofsymbols@gmail.com - 2017-06-12 05:30 -0700
Re: memscan() function or equivalent Ike Naar <ike@iceland.freeshell.org> - 2017-06-12 13:51 +0000
Re: memscan() function or equivalent bartc <bc@freeuk.com> - 2017-06-12 15:04 +0100
Re: memscan() function or equivalent Ike Naar <ike@iceland.freeshell.org> - 2017-06-12 21:26 +0000
Re: memscan() function or equivalent "Patrick.Schluter" <Patrick.Schluter@free.fr> - 2017-06-11 10:04 +0200
Re: memscan() function or equivalent GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-11 10:13 +0200
Re: memscan() function or equivalent "Patrick.Schluter" <Patrick.Schluter@free.fr> - 2017-06-11 13:38 +0200
Re: memscan() function or equivalent GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-11 14:18 +0200
Re: memscan() function or equivalent supercat@casperkitty.com - 2017-06-11 09:57 -0700
Re: memscan() function or equivalent Melzzzzz <Melzzzzz@zzzzz.com> - 2017-06-11 17:18 +0000
Re: memscan() function or equivalent "Patrick.Schluter" <Patrick.Schluter@free.fr> - 2017-06-11 09:53 +0200
Re: memscan() function or equivalent GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-11 10:00 +0200
Re: memscan() function or equivalent "Patrick.Schluter" <Patrick.Schluter@free.fr> - 2017-06-11 13:41 +0200
Re: memscan() function or equivalent GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-07 21:24 +0200
Re: memscan() function or equivalent GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-07 21:55 +0200
Re: memscan() function or equivalent Gareth Owen <gwowen@gmail.com> - 2017-06-07 20:54 +0100
Re: memscan() function or equivalent David Brown <david.brown@hesbynett.no> - 2017-06-07 23:00 +0200
Re: memscan() function or equivalent Gareth Owen <gwowen@gmail.com> - 2017-06-08 08:16 +0100
Re: memscan() function or equivalent David Brown <david.brown@hesbynett.no> - 2017-06-08 10:55 +0200
Re: memscan() function or equivalent Gareth Owen <gwowen@gmail.com> - 2017-06-08 11:44 +0100
Re: memscan() function or equivalent David Brown <david.brown@hesbynett.no> - 2017-06-08 13:11 +0200
Re: memscan() function or equivalent Gareth Owen <gwowen@gmail.com> - 2017-06-08 13:45 +0100
Re: memscan() function or equivalent David Brown <david.brown@hesbynett.no> - 2017-06-08 14:51 +0200
Re: memscan() function or equivalent supercat@casperkitty.com - 2017-06-08 08:00 -0700
Re: memscan() function or equivalent Tim Rentsch <txr@alumni.caltech.edu> - 2017-06-09 12:26 -0700
Re: memscan() function or equivalent Gareth Owen <gwowen@gmail.com> - 2017-06-10 07:24 +0100
Re: memscan() function or equivalent Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-06-10 13:17 +0100
Re: memscan() function or equivalent Gareth Owen <gwowen@gmail.com> - 2017-06-10 17:18 +0100
Re: memscan() function or equivalent Ike Naar <ike@iceland.freeshell.org> - 2017-06-11 18:11 +0000
Re: memscan() function or equivalent Tim Rentsch <txr@alumni.caltech.edu> - 2017-06-11 15:08 -0700
Re: memscan() function or equivalent Gareth Owen <gwowen@gmail.com> - 2017-06-12 18:34 +0100
Re: memscan() function or equivalent Tim Rentsch <txr@alumni.caltech.edu> - 2017-06-14 09:52 -0700
Re: memscan() function or equivalent Gareth Owen <gwowen@gmail.com> - 2017-06-14 19:56 +0100
Re: memscan() function or equivalent Keith Thompson <kst-u@mib.org> - 2017-06-14 12:20 -0700
Re: memscan() function or equivalent Tim Rentsch <txr@alumni.caltech.edu> - 2017-06-17 06:37 -0700
Re: memscan() function or equivalent supercat@casperkitty.com - 2017-06-17 10:02 -0700
Re: memscan() function or equivalent David Brown <david.brown@hesbynett.no> - 2017-06-07 16:51 +0200
Re: memscan() function or equivalent GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-07 17:00 +0200
Re: memscan() function or equivalent supercat@casperkitty.com - 2017-06-07 08:53 -0700
Page 5 of 7 — ← Prev page 1 2 3 4 [5] 6 7 Next page →
| From | bartc <bc@freeuk.com> |
|---|---|
| Date | 2017-06-11 20:22 +0100 |
| Message-ID | <aMg%A.20830$yv7.1739@fx28.am4> |
| In reply to | #111975 |
On 11/06/2017 19:36, Ike Naar wrote:
> On 2017-06-11, bartc <bc@freeuk.com> wrote:
>> The trouble is that the following has the same structure:
>>
>> L231:
>> if (n--) goto L232;
>> {
>> a[++i] = n;
>> goto L213;
>> }
>> L232:
>>
>> but now does something quite different. It is much less robust.
>
> What's the difference (except for the L231 <-> L213 typo)?
> If the typo is the point you're making, it's not a strong point,
> because a typo in the stuctured while loop would also lead to
> incorrect behaviour.
It wouldn't pass control to some random place in the function. Without
using goto, once a while loop is entered, it can't go anywhere else in
the function except to the end of the loop.
My other post [2 1/2 hours later than the above] expands on this example
with some actual tested code, and brings up a couple of other points.
--
bartc
[toc] | [prev] | [next] | [standalone]
| From | Ike Naar <ike@iceland.freeshell.org> |
|---|---|
| Date | 2017-06-12 06:09 +0000 |
| Message-ID | <slrn3vfsojsc6q.9t4.ike@iceland.freeshell.org> |
| In reply to | #111976 |
On 2017-06-11, bartc <bc@freeuk.com> wrote:
> On 11/06/2017 19:36, Ike Naar wrote:
>> On 2017-06-11, bartc <bc@freeuk.com> wrote:
>
>>> The trouble is that the following has the same structure:
>>>
>>> L231:
>>> if (n--) goto L232;
>>> {
>>> a[++i] = n;
>>> goto L213;
>>> }
>>> L232:
>>>
>>> but now does something quite different. It is much less robust.
And it's still wrong. The condition for 'goto L232' should be
the negation of what's written.
>> What's the difference (except for the L231 <-> L213 typo)?
>> If the typo is the point you're making, it's not a strong point,
>> because a typo in the stuctured while loop would also lead to
>> incorrect behaviour.
>
> It wouldn't pass control to some random place in the function. Without
> using goto, once a while loop is entered, it can't go anywhere else in
> the function except to the end of the loop.
>
> My other post [2 1/2 hours later than the above] expands on this example
> with some actual tested code, and brings up a couple of other points.
Sorry, I can't find that post, can you provide a message id?
[toc] | [prev] | [next] | [standalone]
| From | bartc <bc@freeuk.com> |
|---|---|
| Date | 2017-06-12 10:38 +0100 |
| Message-ID | <iit%A.43332$D15.39465@fx39.am4> |
| In reply to | #111992 |
On 12/06/2017 07:09, Ike Naar wrote:
> On 2017-06-11, bartc <bc@freeuk.com> wrote:
>> On 11/06/2017 19:36, Ike Naar wrote:
>>> On 2017-06-11, bartc <bc@freeuk.com> wrote:
>>
>>>> The trouble is that the following has the same structure:
>>>>
>>>> L231:
>>>> if (n--) goto L232;
>>>> {
>>>> a[++i] = n;
>>>> goto L213;
>>>> }
>>>> L232:
>>>>
>>>> but now does something quite different. It is much less robust.
>
> And it's still wrong. The condition for 'goto L232' should be
> the negation of what's written.
>
>>> What's the difference (except for the L231 <-> L213 typo)?
>>> If the typo is the point you're making, it's not a strong point,
>>> because a typo in the stuctured while loop would also lead to
>>> incorrect behaviour.
>>
>> It wouldn't pass control to some random place in the function. Without
>> using goto, once a while loop is entered, it can't go anywhere else in
>> the function except to the end of the loop.
>>
>> My other post [2 1/2 hours later than the above] expands on this example
>> with some actual tested code, and brings up a couple of other points.
>
> Sorry, I can't find that post, can you provide a message id?
Easier just to repeat it (in reply to GOTHIER Nathan who was claiming
that goto code written manually with block structure and meaningful
label names could be robust):
---------------------------------------------------------------------
OK, here's a real piece of C code, for the same task:
int i,t,iter,prime,k;
count=0;
for (iter=1; iter<=20000; ++iter) {
for (i=1; i<=size; ++i) {
data[i]=1;
}
for (i=1; i<=size; ++i) {
if (data[i]) {
prime = i*2+3;
k = i+prime;
while (k<=size) {
data[k]=0;
k=k+prime;
}
++count;
}
}
}
Here's same code, minus the explicit loop [statement]s:
int i,t,iter,prime,k;
count=0;
iter=1;
outerloop:
{
i=1;
copyloop:
{
data[i]=1;
++i;
if (i<=size) goto copyloop;
}
i=1;
mainloop:
{
if (data[i]) {
prime = i*2+3;
k = i+prime;
innerloop:
{
if (k>size) goto endinnerloop;
data[k]=0;
k=k+prime;
goto innerloop;
}
endinnerloop:
++count;
}
++i;
if (i<=size) goto mainloop;
}
++iter;
if (iter<=20000) goto outerloop;
}
Here, I was able to use my knowledge of the values to move the loop
tests to the end of the loop in some cases, which is tidier. However, if
in future that changes because the limits are no longer constants, then
this code won't automatically change (as happens with a
compiler-constructed loop), and it may not work properly.
So it's more fragile. Also, as I pointed out before, it is very easy to
write mainloop instead of copyloop, etc and the compiler won't detect
the error. Again fragile.
In addition, if I needed to duplicate the body of copyloop for example
further down the function, then I would need to remember to create a new
label for it, and to change the name of the embedded goto label. If I
don't... well that is once more fragile.
That's why people avoid things like goto unless there is no easy
alternative. It is error prone and can render code unreadable. And
harder to translate code to another language when that language doesn't
have goto, or its use is prohibited.
--
bartc
[toc] | [prev] | [next] | [standalone]
| From | asetofsymbols@gmail.com |
|---|---|
| Date | 2017-06-12 05:30 -0700 |
| Message-ID | <b929c11c-99a9-4394-a927-7227e859c1de@googlegroups.com> |
| In reply to | #111998 |
int i,t,iter,prime,k;
count=0;
for (iter=1; iter<=20000; ++iter) {
for (i=1; i<=size; ++i) {
data[i]=1;
}
#define G(a,b) if(a)goto b
iter=1;G(1,a3);
a0: i=1; G(1,a2);
a1: data[i++]; a2:G( i<=size,a1);
++iter; a3:G(iter<=size,a0);
for (i=1; i<=size; ++i) {
if (data[i]) {
prime = i*2+3;
k = i+prime;
while (k<=size) {
data[k]=0;
k=k+prime;
}
++count;
}
}
}
I think count is as i...
i=1;G(1,a7)
a4: G(!data[i],a6);
prime=i*2+3;k=i+prime; G(1,ax);
a5: data[k]=0;k+=prime;ax: G(k<=size)
a6: ++i;++count;
a7: G(i<=size,a4);
[toc] | [prev] | [next] | [standalone]
| From | Ike Naar <ike@iceland.freeshell.org> |
|---|---|
| Date | 2017-06-12 13:51 +0000 |
| Message-ID | <slrn3vfsojt799.jp9.ike@iceland.freeshell.org> |
| In reply to | #111998 |
On 2017-06-12, bartc <bc@freeuk.com> wrote:
> [...]
> for (i=1; i<=size; ++i) {
> data[i]=1;
> }
> i=1;
vs.
> copyloop:
> {
> data[i]=1;
> ++i;
> if (i<=size) goto copyloop;
> }
The for loop and the copyloop have different semantics for size <= 0 .
[toc] | [prev] | [next] | [standalone]
| From | bartc <bc@freeuk.com> |
|---|---|
| Date | 2017-06-12 15:04 +0100 |
| Message-ID | <Rbx%A.70487$kd6.26814@fx33.am4> |
| In reply to | #112011 |
On 12/06/2017 14:51, Ike Naar wrote:
> On 2017-06-12, bartc <bc@freeuk.com> wrote:
>> [...]
>> for (i=1; i<=size; ++i) {
>> data[i]=1;
>> }
>> i=1;
>
> vs.
>
>> copyloop:
>> {
>> data[i]=1;
>> ++i;
>> if (i<=size) goto copyloop;
>> }
>
> The for loop and the copyloop have different semantics for size <= 0 .
That can't happen.
I did say that I moved the test to the end of the loop because I /knew/
what the limits were (or knew they were not going to be <=0).
But that's also an example of the things people are tempted to do when
coding at a lower level.
--
bartc
[toc] | [prev] | [next] | [standalone]
| From | Ike Naar <ike@iceland.freeshell.org> |
|---|---|
| Date | 2017-06-12 21:26 +0000 |
| Message-ID | <slrn3vfsoju1ui.ovs.ike@iceland.freeshell.org> |
| In reply to | #111976 |
On 2017-06-11, bartc <bc@freeuk.com> wrote:
> On 11/06/2017 19:36, Ike Naar wrote:
>> On 2017-06-11, bartc <bc@freeuk.com> wrote:
>
>>> The trouble is that the following has the same structure:
>>>
>>> L231:
>>> if (n--) goto L232;
>>> {
>>> a[++i] = n;
>>> goto L213;
>>> }
>>> L232:
>>>
>>> but now does something quite different. It is much less robust.
>>
>> What's the difference (except for the L231 <-> L213 typo)?
>> If the typo is the point you're making, it's not a strong point,
>> because a typo in the stuctured while loop would also lead to
>> incorrect behaviour.
>
> It wouldn't pass control to some random place in the function. Without
> using goto, once a while loop is entered, it can't go anywhere else in
> the function except to the end of the loop.
That's wishful thinking. Consider the original structured while loop:
while (n--) {
a[++i] = n;
}
Suppose that, due to a typo, this is changed to
while (n--) {
a[++j] = n;
}
that is, the 'i' of the array index is replaced by a 'j'.
Then the assignment to the array element may write to a location
that is outside the array bounds, corrupting memory that might
contain a function pointer or a return address; control might pass
to that function pointer or return address.
[toc] | [prev] | [next] | [standalone]
| From | "Patrick.Schluter" <Patrick.Schluter@free.fr> |
|---|---|
| Date | 2017-06-11 10:04 +0200 |
| Message-ID | <593cf986$0$15324$426a34cc@news.free.fr> |
| In reply to | #111939 |
Le 10.06.2017 à 23:40, GOTHIER Nathan a écrit : > On Sat, 10 Jun 2017 11:52:29 -0700 (PDT) > David Kleinecke <dkleinecke@gmail.com> wrote: > >> But from the point of view of what is easier to "understand" I >> suspect the form in goto's has more popular appeal. > > Indeed. I am stunned by the fierce opposition to labels and goto while many > detractors acknowledge its incredible power for corner cases where they are > unable to express clearly their algorithm with a higher level loop structure. That's not the case with your example, it can be properly an completely expressed by a while, no need to use goto. > > I suspect that they are too full of themselves to accept with humility to use > labels and goto to draft their code before possibly improving its clarity with > higher level loop structures such as while or for. It's the old story of bottom-up vs top-down. The bottom-up people tend to drawn in the details and often lose focus. The top-down people have a tendency to forget the details that makes a good product. A good equilibrum between both tendencies is what's called for. > > Actually I prefer to draft loops with labels and goto to tell the machine how I > want to process the data instead of restricting my code with high level loop > structures. > > I think it is a better approach to start from a lower level than wasting a lot > of time to think directly from a high level. The simple fact that some peoples > are "forced" with an unecessary shame to use labels and goto in corner cases > proves they failed in their top-down approach which isn't straightforward for > any algorithm. Then do assembly. > > I have a trivial question for the top-down masters: did you learn the number > theory before counting upto 10 at the kindergarten? :o) > And obviously, you stayed at kindergarten level :-) (you counted on your fingers during number theory class).
[toc] | [prev] | [next] | [standalone]
| From | GOTHIER Nathan <nathan.gothier@gmail.com> |
|---|---|
| Date | 2017-06-11 10:13 +0200 |
| Message-ID | <20170611101316.1b37350f59c2ec2406d0e800@gmail.com> |
| In reply to | #111958 |
On Sun, 11 Jun 2017 10:04:23 +0200 "Patrick.Schluter" <Patrick.Schluter@free.fr> wrote: > Then do assembly. Do you really know the reason why Dennis RITCHIE invented C? I don't think so. > And obviously, you stayed at kindergarten level :-) (you counted on your > fingers during number theory class). Yet an other insult... you're pathetic!
[toc] | [prev] | [next] | [standalone]
| From | "Patrick.Schluter" <Patrick.Schluter@free.fr> |
|---|---|
| Date | 2017-06-11 13:38 +0200 |
| Message-ID | <593d2bac$0$4839$426a34cc@news.free.fr> |
| In reply to | #111961 |
Le 11.06.2017 à 10:13, GOTHIER Nathan a écrit : > On Sun, 11 Jun 2017 10:04:23 +0200 > "Patrick.Schluter" <Patrick.Schluter@free.fr> wrote: > >> Then do assembly. > > Do you really know the reason why Dennis RITCHIE invented C? I don't think so. > > >> And obviously, you stayed at kindergarten level :-) (you counted on your >> fingers during number theory class). > > Yet an other insult... you're pathetic! > C'est celui qui dit qui est.
[toc] | [prev] | [next] | [standalone]
| From | GOTHIER Nathan <nathan.gothier@gmail.com> |
|---|---|
| Date | 2017-06-11 14:18 +0200 |
| Message-ID | <20170611141851.e272f1b856bb46c18ab7e5ab@gmail.com> |
| In reply to | #111968 |
On Sun, 11 Jun 2017 13:38:21 +0200 "Patrick.Schluter" <Patrick.Schluter@free.fr> wrote: > C'est celui qui dit qui est. You should grow up... I won't answer to your childish behavior any longer.
[toc] | [prev] | [next] | [standalone]
| From | supercat@casperkitty.com |
|---|---|
| Date | 2017-06-11 09:57 -0700 |
| Message-ID | <623ee0af-f411-4800-b61d-7db8e6f9857e@googlegroups.com> |
| In reply to | #111961 |
On Sunday, June 11, 2017 at 3:16:40 AM UTC-5, GOTHIER Nathan wrote: > On Sun, 11 Jun 2017 10:04:23 +0200 > "Patrick.Schluter" wrote: > > Then do assembly. > > Do you really know the reason why Dennis RITCHIE invented C? I don't think so. A lot of people seem to think that people wanting to do low-level programming should use assembly rather than C. Perhaps these people want C to be more elegant, and regard those who want to do ugly low-level stuff with it as interfering with that. A language that only tries to support application requirements that can be expressed elegantly can be much cleaner than one that is supposed to be suitable for a wider range of purposes. If, however, a programmer needs to end up with machine code that meets an icky set of requirements, a language that can meet those requirements will be much more useful than one that cannot. If a language doesn't allow something to be expressed particularly elegantly, being able to express it inelegantly may be better than being unable to express it at all, or being limited to expressing it in ways that are downright horrible.
[toc] | [prev] | [next] | [standalone]
| From | Melzzzzz <Melzzzzz@zzzzz.com> |
|---|---|
| Date | 2017-06-11 17:18 +0000 |
| Message-ID | <ohju1n$sn4$1@news.albasani.net> |
| In reply to | #111972 |
On 2017-06-11, supercat@casperkitty.com <supercat@casperkitty.com> wrote: > On Sunday, June 11, 2017 at 3:16:40 AM UTC-5, GOTHIER Nathan wrote: >> On Sun, 11 Jun 2017 10:04:23 +0200 >> "Patrick.Schluter" wrote: >> > Then do assembly. >> >> Do you really know the reason why Dennis RITCHIE invented C? I don't think so. > > A lot of people seem to think that people wanting to do low-level > programming should use assembly rather than C. Perhaps these people > want C to be more elegant, and regard those who want to do ugly > low-level stuff with it as interfering with that. A language that > only tries to support application requirements that can be expressed > elegantly can be much cleaner than one that is supposed to be > suitable for a wider range of purposes. If, however, a programmer > needs to end up with machine code that meets an icky set of requirements, > a language that can meet those requirements will be much more useful than > one that cannot. If a language doesn't allow something to be expressed > particularly elegantly, being able to express it inelegantly may be > better than being unable to express it at all, or being limited to > expressing it in ways that are downright horrible. Assembler is just for fun these days, or if C compiler on particular embedded processor does not produce optimal code. -- press any key to continue or any other to quit...
[toc] | [prev] | [next] | [standalone]
| From | "Patrick.Schluter" <Patrick.Schluter@free.fr> |
|---|---|
| Date | 2017-06-11 09:53 +0200 |
| Message-ID | <593cf6fa$0$3612$426a34cc@news.free.fr> |
| In reply to | #111929 |
Le 10.06.2017 à 17:38, GOTHIER Nathan a écrit : > On Sat, 10 Jun 2017 17:14:19 +0200 > "Patrick.Schluter" <Patrick.Schluter@free.fr> wrote: > >> I understad low level very well, thank you very much, that's why I avoid >> it when it is not necessary and HERE it is not necessary. Using goto to >> simulate a simple while/for loop, is like cleaning your toilet with a >> toothbrush, it gets the job done but is more difficult for no practical >> benefit. >> Trying to defend that with the argument of it being a low level prowess >> only shows your limitations. > > You're right, my brain is quite limited but insulting people for knowing their > own limits by using a basic feature of C only shows your lack of humanism. You started the insulting by suggesting I wouldn't be able to understand low level, which is ludicrous as that is not low level, it's only obfuscation. I > never insulted anybody for not writing C in a specific programming style but > there are many people here thinking it is their duty to do so... I responded in kind when you suggested I could not understand low level, which is insulting. And that only for remarking that there is no point in using C as if it were assembly, i.e. by throwing away the strength of abstractions. > > Actually I find for or while loop straightforward in some regular pattern but I > prefer to draft with labels and goto before finalizing the code. > > Many artists use pencils before inking their drawings. Should you also insult > them for not using ink like a true wonderful artist? > No, they wouldn't start a drawing by building a pencil from wood an charcoal and making the paper from pulp first.
[toc] | [prev] | [next] | [standalone]
| From | GOTHIER Nathan <nathan.gothier@gmail.com> |
|---|---|
| Date | 2017-06-11 10:00 +0200 |
| Message-ID | <20170611100047.ef4e78d99c307259bb7d6c1c@gmail.com> |
| In reply to | #111956 |
On Sun, 11 Jun 2017 09:53:30 +0200 "Patrick.Schluter" <Patrick.Schluter@free.fr> wrote: > You started the insulting by suggesting I wouldn't be able to understand > low level, which is ludicrous as that is not low level, it's only > obfuscation. Are you kidding? On Sat, 10 Jun 2017 09:08:07 +0200 "Patrick.Schluter" <Patrick.Schluter@free.fr> wrote: > There's nothing wrong with goto in some cases. > In this case it is beyond stupid... Don't try to justify yourself with bad excuses after shooting on people. It only shows the fact you're unable to take any responsibility for your own actions.
[toc] | [prev] | [next] | [standalone]
| From | "Patrick.Schluter" <Patrick.Schluter@free.fr> |
|---|---|
| Date | 2017-06-11 13:41 +0200 |
| Message-ID | <593d2c51$0$4839$426a34cc@news.free.fr> |
| In reply to | #111957 |
Le 11.06.2017 à 10:00, GOTHIER Nathan a écrit : > On Sun, 11 Jun 2017 09:53:30 +0200 > "Patrick.Schluter" <Patrick.Schluter@free.fr> wrote: > >> You started the insulting by suggesting I wouldn't be able to understand >> low level, which is ludicrous as that is not low level, it's only >> obfuscation. > > Are you kidding? > No, it shows that you do not even comprehend the shit you write. > On Sat, 10 Jun 2017 09:08:07 +0200 > "Patrick.Schluter" <Patrick.Schluter@free.fr> wrote: > >> There's nothing wrong with goto in some cases. >> In this case it is beyond stupid... > > Don't try to justify yourself with bad excuses after shooting on people. It > only shows the fact you're unable to take any responsibility for your own > actions. > I have, it is beyond stupid to use a goto in that case, I repeat and I assume it. It is you that try pathetically to justify the injustifyable.
[toc] | [prev] | [next] | [standalone]
| From | GOTHIER Nathan <nathan.gothier@gmail.com> |
|---|---|
| Date | 2017-06-07 21:24 +0200 |
| Message-ID | <20170607212451.875f2012f9df75f316acc939@gmail.com> |
| In reply to | #111745 |
On Wed, 7 Jun 2017 21:15:28 +0200 "Patrick.Schluter" <Patrick.Schluter@free.fr> wrote: > That's not what the const denotes. THAT const tells that the function > doesn't modify the data pointed to. The pointer itself is modifiable at > leisure. I always mixed both cases since the syntax is ambiguous.
[toc] | [prev] | [next] | [standalone]
| From | GOTHIER Nathan <nathan.gothier@gmail.com> |
|---|---|
| Date | 2017-06-07 21:55 +0200 |
| Message-ID | <20170607215554.8e58c27bddb9b7ddac12e9b3@gmail.com> |
| In reply to | #111745 |
On Wed, 7 Jun 2017 21:15:28 +0200 "Patrick.Schluter" <Patrick.Schluter@free.fr> wrote: > It's an unsigned, so even if(n) is enough. It may be enough but not idiomatic as you like to repeat when the style isn't yours...
[toc] | [prev] | [next] | [standalone]
| From | Gareth Owen <gwowen@gmail.com> |
|---|---|
| Date | 2017-06-07 20:54 +0100 |
| Message-ID | <87wp8n4lqm.fsf@gmail.com> |
| In reply to | #111711 |
Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
> What is the general view of writing things like
>
> k += *s0 == c0;
>
> ? I find it compact and natural with no extra cost, at least with
> modern compilers.
I don't madly care for it. My brain has to work to spot which is the
assignment, and which is the comparison.
I'd probably write
if(*s0 == c0) k = k+1;
That's comprehensible to any programmer anywhere, and idiomatic in
almost every major imperative language - as well as directly expressing
what you want to do
Which of these is clearest:
"If the characters match, increment the counter".
"Increment the counter by one if the characters match,
or zero if they don't"
They're logically equivalent identical, but one of those reads like I
think, and one of them reads like it was written by a Cylon.
I'd also consider
k += (*s0 == c0);
preferable to yours. I find it simply easier to parse mentally without
back-tracking.
Any compiler that produces different code for these should be taken out
and shot.
[toc] | [prev] | [next] | [standalone]
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Date | 2017-06-07 23:00 +0200 |
| Message-ID | <oh9pan$9g3$1@dont-email.me> |
| In reply to | #111749 |
On 07/06/17 21:54, Gareth Owen wrote: > Ben Bacarisse <ben.usenet@bsb.me.uk> writes: > >> What is the general view of writing things like >> >> k += *s0 == c0; >> >> ? I find it compact and natural with no extra cost, at least with >> modern compilers. > > I don't madly care for it. My brain has to work to spot which is the > assignment, and which is the comparison. > > I'd probably write > > if(*s0 == c0) k = k+1; > > > That's comprehensible to any programmer anywhere, and idiomatic in > almost every major imperative language - as well as directly expressing > what you want to do > > Which of these is clearest: > "If the characters match, increment the counter". > "Increment the counter by one if the characters match, > or zero if they don't" > > They're logically equivalent identical, but one of those reads like I > think, and one of them reads like it was written by a Cylon. > > I'd also consider > > k += (*s0 == c0); > > preferable to yours. I find it simply easier to parse mentally without > back-tracking. > I would also prefer to have these extra parenthesis. > Any compiler that produces different code for these should be taken out > and shot. > A compiler could reasonably produce different code for the "if" version (but not for the version with extra parenthesis). In some cases, a conditional branch would be more efficient, in other cases an integer selection instruction or some other way of producing a 0 or 1, followed by an unconditional add, would be best. A compiler /could/ choose the method it thought was most efficient, but it could also reasonably choose the method that matched the source code best, on the assumption that the programmer knows best.
[toc] | [prev] | [next] | [standalone]
Page 5 of 7 — ← Prev page 1 2 3 4 [5] 6 7 Next page →
Back to top | Article view | comp.lang.c
csiph-web