Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Simulations are like miniskirts, they show a lot and hide the essentials. -- Hubert Kirrman


devel / comp.lang.c / Re: What part of... (Well, you know the rest!) (Was: gosub.c)

SubjectAuthor
* gosub.cluser droog
+* Re: gosub.cOtto J. Makela
|`- Re: gosub.cStefan Ram
+* Re: gosub.cAndreas Kempe
|+* Re: gosub.cStefan Ram
||`- Re: gosub.cAndreas Kempe
|+- Re: gosub.cluser droog
|`- Re: gosub.cAndrey Tarasevich
`* Re: gosub.cBonita Montero
 +* What part of... (Well, you know the rest!) (Was: gosub.c)Kenny McCormack
 |`* Re: What part of... (Well, you know the rest!) (Was: gosub.c)Bonita Montero
 | `* Re: What part of... (Well, you know the rest!) (Was: gosub.c)Anton Shepelev
 |  +* Re: What part of... (Well, you know the rest!) (Was: gosub.c)Malcolm McLean
 |  |`- Re: What part of... (Well, you know the rest!) (Was: gosub.c)Bonita Montero
 |  +- Re: What part of... (Well, you know the rest!) (Was: gosub.c)Bonita Montero
 |  `- Re: What part of... (Well, you know the rest!) (Was: gosub.c)Tim Rentsch
 `- Re: gosub.cluser droog

1
gosub.c

<cf49401f-eae2-486d-bcf8-4550e8de5467n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21156&group=comp.lang.c#21156

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:6214:e66:b0:441:7695:8eb7 with SMTP id jz6-20020a0562140e6600b0044176958eb7mr1971975qvb.127.1649732996111;
Mon, 11 Apr 2022 20:09:56 -0700 (PDT)
X-Received: by 2002:a05:6830:138d:b0:5b2:4b0a:a4fa with SMTP id
d13-20020a056830138d00b005b24b0aa4famr12597353otq.380.1649732995770; Mon, 11
Apr 2022 20:09:55 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Mon, 11 Apr 2022 20:09:55 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=24.207.213.87; posting-account=G1KGwgkAAAAyw4z0LxHH0fja6wAbo7Cz
NNTP-Posting-Host: 24.207.213.87
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <cf49401f-eae2-486d-bcf8-4550e8de5467n@googlegroups.com>
Subject: gosub.c
From: luser.dr...@gmail.com (luser droog)
Injection-Date: Tue, 12 Apr 2022 03:09:56 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 25
 by: luser droog - Tue, 12 Apr 2022 03:09 UTC

Found this on my disk. I forget where/why it came from but I
thought it was fun enough to share.

% cat gosub.c
#include <stdio.h>

#define GOSUB(target) do { *stk++ = __LINE__; goto target; case __LINE__: ;} while(0)
#define RETURN() do{ target = *--stk; goto Goto; } while(0)

int main(){
int *stk = (int [10]){};
int target = 0;
Goto: switch( target ){
default:
puts("program begins.");
GOSUB(test_label);
puts("program continues.");
GOSUB(test_label);
puts("program ends.");
return 0;
test_label:
puts("gosub successful.");
RETURN();
}
}

Re: gosub.c

<87bkwxa0e2.fsf@tigger.extechop.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21276&group=comp.lang.c#21276

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: om...@iki.fi (Otto J. Makela)
Newsgroups: comp.lang.c
Subject: Re: gosub.c
Date: Tue, 19 Apr 2022 12:27:33 +0300
Organization: Games and Theory
Lines: 11
Message-ID: <87bkwxa0e2.fsf@tigger.extechop.net>
References: <cf49401f-eae2-486d-bcf8-4550e8de5467n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="960b5606b0d908f18b850789a8fbe0c4";
logging-data="10682"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19pdMSOOpCw6GFH7hMfBC9q"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:Is3zI8Jvl1L7AUFSNQr0bgFV2v4=
sha1:piu1IE+z4C8IYu7Agul+I2H+y2g=
X-Face: 'g'S,X"!c;\pfvl4ljdcm?cDdk<-Z;`x5;YJPI-cs~D%;_<\V3!3GCims?a*;~u$<FYl@"E
c?3?_J+Zwn~{$8<iEy}EqIn_08"`oWuqO$#(5y3hGq8}BG#sag{BL)u8(c^Lu;*{8+'Z-k\?k09ILS
X-URL: http://www.iki.fi/om/
Mail-Copies-To: never
 by: Otto J. Makela - Tue, 19 Apr 2022 09:27 UTC

luser droog <luser.droog@gmail.com> wrote:

> Found this on my disk. I forget where/why it came from but I
> thought it was fun enough to share.

That was... worthy of the obfuscated C competition. Thanks, I hate it.
--
/* * * Otto J. Makela <om@iki.fi> * * * * * * * * * */
/* Phone: +358 40 765 5772, ICBM: N 60 10' E 24 55' */
/* Mail: Mechelininkatu 26 B 27, FI-00100 Helsinki */
/* * * Computers Rule 01001111 01001011 * * * * * * */

Re: gosub.c

<GOSUB-20220419162145@ram.dialup.fu-berlin.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21284&group=comp.lang.c#21284

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.c
Subject: Re: gosub.c
Date: 19 Apr 2022 15:22:35 GMT
Organization: Stefan Ram
Lines: 18
Expires: 1 Apr 2023 11:59:58 GMT
Message-ID: <GOSUB-20220419162145@ram.dialup.fu-berlin.de>
References: <cf49401f-eae2-486d-bcf8-4550e8de5467n@googlegroups.com> <87bkwxa0e2.fsf@tigger.extechop.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de 0EBnMo38U7Vsz7qPYHdVfAUHaWrqgHNlaCcaRNIjT87brM
X-Copyright: (C) Copyright 2022 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Tue, 19 Apr 2022 15:22 UTC

om@iki.fi (Otto J. Makela) writes:
>That was... worthy of the obfuscated C competition.

The code given was quite clear. Still, such a macro is not
particularly elegant.

Indeed, I sometimes miss GOSUB in C.

When I have a function with many local names, and want to
add some structure to it, I might use a separate function
as a subroutine, but then I might have to write a lot of
parameter declarations, which might also be deemed to be
some kind of obfuscation. Today, optimizing compilers can
make sure that there will be no run-time penalty for this,
but there still is this write-time penalty. A GOSUB would
be less cumbersome and more clear in such cases.

Re: gosub.c

<t3p674$99q$1@nyheter.lysator.liu.se>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21324&group=comp.lang.c#21324

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!nyheter.lysator.liu.se!.POSTED!not-for-mail
From: kem...@lysator.liu.se (Andreas Kempe)
Newsgroups: comp.lang.c
Subject: Re: gosub.c
Date: Wed, 20 Apr 2022 14:43:48 -0000 (UTC)
Organization: Lysator ACS
Message-ID: <t3p674$99q$1@nyheter.lysator.liu.se>
References: <cf49401f-eae2-486d-bcf8-4550e8de5467n@googlegroups.com>
Injection-Date: Wed, 20 Apr 2022 14:43:48 -0000 (UTC)
Injection-Info: nyheter.lysator.liu.se; posting-account="kempe";
logging-data="9530"; mail-complaints-to="newsmaster@lysator.liu.se"
User-Agent: slrn/1.0.3 (FreeBSD)
 by: Andreas Kempe - Wed, 20 Apr 2022 14:43 UTC

Den 2022-04-12 skrev luser droog <luser.droog@gmail.com>:
> Found this on my disk. I forget where/why it came from but I
> thought it was fun enough to share.
>

It was well worth sharing!

>
> % cat gosub.c
> #include <stdio.h>
>
> #define GOSUB(target) do { *stk++ = __LINE__; goto target; case __LINE__: ;} while(0)
> #define RETURN() do{ target = *--stk; goto Goto; } while(0)
>
> int main(){
> int *stk = (int [10]){};
> int target = 0;
> Goto: switch( target ){
> default:
> puts("program begins.");
> GOSUB(test_label);
> puts("program continues.");
> GOSUB(test_label);
> puts("program ends.");
> return 0;
> test_label:
> puts("gosub successful.");
> RETURN();
> }
> }

I tried throwing this code at clang 10.0.1 with -O3 on an amd64 system
and it produced some, to me, surprising results. I expected the
compiler to turn the code into

int main()
{ puts("program begins.");
puts("gosub successful.");
puts("program continues.");
puts("gosub successful.");
puts("program ends.");
return 0;
}

but I got something along the lines of (assembler turned back into C
by hand)

int main()
{ int value = 0;

goto begin;

print_continue:
puts("program continues.");
value = 0xe;

print_gosub:
puts("gosub successful.");

begin:
if (value == 0xc)
goto print_continue;
if (value == 0xe)
goto print_end;

puts("program begins.");
value = 0xc;
goto print_gosub;

print_end:
puts("program ends.");
return 0;
}

I have a hard time imagining that this construct would be more
efficient than simply printing the output in sequence. Is it the
switch-case construct causing the compiler to organise the code the
way it does?

Re: gosub.c

<optimization-20220420160032@ram.dialup.fu-berlin.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21325&group=comp.lang.c#21325

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.c
Subject: Re: gosub.c
Date: 20 Apr 2022 15:02:03 GMT
Organization: Stefan Ram
Lines: 25
Expires: 1 Apr 2023 11:59:58 GMT
Message-ID: <optimization-20220420160032@ram.dialup.fu-berlin.de>
References: <cf49401f-eae2-486d-bcf8-4550e8de5467n@googlegroups.com> <t3p674$99q$1@nyheter.lysator.liu.se>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de OXjF7G7dFOCZPxdnQXcCPAT3slf34fpmz7cquBxI9vb6gp
X-Copyright: (C) Copyright 2022 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Wed, 20 Apr 2022 15:02 UTC

Andreas Kempe <kempe@lysator.liu.se> writes:
>int main()
>{
> puts("program begins.");
> puts("gosub successful.");
> puts("program continues.");
> puts("gosub successful.");
> puts("program ends.");
> return 0;
>}

Here,

leaq .LC0(%rip), %rcx; call puts
leaq .LC1(%rip), %rcx; call puts
leaq .LC2(%rip), %rcx; call puts
leaq .LC1(%rip), %rcx; call puts
leaq .LC3(%rip), %rcx; call puts

, assembler simplified and reformatted by hand, two
operations per line. gcc estimated to be not older than
5 years, options including "-march=native -Ofast -O3".

Re: gosub.c

<t3p8sp$99q$2@nyheter.lysator.liu.se>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21327&group=comp.lang.c#21327

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!nyheter.lysator.liu.se!.POSTED!not-for-mail
From: kem...@lysator.liu.se (Andreas Kempe)
Newsgroups: comp.lang.c
Subject: Re: gosub.c
Date: Wed, 20 Apr 2022 15:29:29 -0000 (UTC)
Organization: Lysator ACS
Message-ID: <t3p8sp$99q$2@nyheter.lysator.liu.se>
References: <cf49401f-eae2-486d-bcf8-4550e8de5467n@googlegroups.com>
<t3p674$99q$1@nyheter.lysator.liu.se>
<optimization-20220420160032@ram.dialup.fu-berlin.de>
Injection-Date: Wed, 20 Apr 2022 15:29:29 -0000 (UTC)
Injection-Info: nyheter.lysator.liu.se; posting-account="kempe";
logging-data="9530"; mail-complaints-to="newsmaster@lysator.liu.se"
User-Agent: slrn/1.0.3 (FreeBSD)
 by: Andreas Kempe - Wed, 20 Apr 2022 15:29 UTC

Den 2022-04-20 skrev Stefan Ram <ram@zedat.fu-berlin.de>:
> Andreas Kempe <kempe@lysator.liu.se> writes:
>>int main()
>>{
>> puts("program begins.");
>> puts("gosub successful.");
>> puts("program continues.");
>> puts("gosub successful.");
>> puts("program ends.");
>> return 0;
>>}
>
> Here,
>
> leaq .LC0(%rip), %rcx; call puts
> leaq .LC1(%rip), %rcx; call puts
> leaq .LC2(%rip), %rcx; call puts
> leaq .LC1(%rip), %rcx; call puts
> leaq .LC3(%rip), %rcx; call puts
>
> , assembler simplified and reformatted by hand, two
> operations per line. gcc estimated to be not older than
> 5 years, options including "-march=native -Ofast -O3".
>

I tried it on GCC 10.3.0 and got the same result as you, I also tried
it on another system with a newer llvm, clang version 13.0.1, and it
produced the same result as my first llvm attempt.

Interesting that GCC seems to provide a better optimisation than llvm
in this case. I'm not well versed enough in compiler construction to
say why.

Re: gosub.c

<9ed2a0c5-ddb6-435b-a19f-2a772967728an@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21338&group=comp.lang.c#21338

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:ac8:7fcd:0:b0:2f3:3cb5:42b9 with SMTP id b13-20020ac87fcd000000b002f33cb542b9mr5412991qtk.559.1650486010432;
Wed, 20 Apr 2022 13:20:10 -0700 (PDT)
X-Received: by 2002:a05:620a:13a3:b0:69e:13f4:6f96 with SMTP id
m3-20020a05620a13a300b0069e13f46f96mr13670116qki.100.1650486010237; Wed, 20
Apr 2022 13:20:10 -0700 (PDT)
Path: i2pn2.org!rocksolid2!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Wed, 20 Apr 2022 13:20:10 -0700 (PDT)
In-Reply-To: <t3p674$99q$1@nyheter.lysator.liu.se>
Injection-Info: google-groups.googlegroups.com; posting-host=24.207.213.87; posting-account=G1KGwgkAAAAyw4z0LxHH0fja6wAbo7Cz
NNTP-Posting-Host: 24.207.213.87
References: <cf49401f-eae2-486d-bcf8-4550e8de5467n@googlegroups.com> <t3p674$99q$1@nyheter.lysator.liu.se>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <9ed2a0c5-ddb6-435b-a19f-2a772967728an@googlegroups.com>
Subject: Re: gosub.c
From: luser.dr...@gmail.com (luser droog)
Injection-Date: Wed, 20 Apr 2022 20:20:10 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 81
 by: luser droog - Wed, 20 Apr 2022 20:20 UTC

On Wednesday, April 20, 2022 at 9:44:01 AM UTC-5, Andreas Kempe wrote:
> Den 2022-04-12 skrev luser droog <luser...@gmail.com>:
> > Found this on my disk. I forget where/why it came from but I
> > thought it was fun enough to share.
> >
> It was well worth sharing!
> >
> > % cat gosub.c
> > #include <stdio.h>
> >
> > #define GOSUB(target) do { *stk++ = __LINE__; goto target; case __LINE__: ;} while(0)
> > #define RETURN() do{ target = *--stk; goto Goto; } while(0)
> >
> > int main(){
> > int *stk = (int [10]){};
> > int target = 0;
> > Goto: switch( target ){
> > default:
> > puts("program begins.");
> > GOSUB(test_label);
> > puts("program continues.");
> > GOSUB(test_label);
> > puts("program ends.");
> > return 0;
> > test_label:
> > puts("gosub successful.");
> > RETURN();
> > }
> > }
> I tried throwing this code at clang 10.0.1 with -O3 on an amd64 system
> and it produced some, to me, surprising results. I expected the
> compiler to turn the code into
>
> int main()
> {
> puts("program begins.");
> puts("gosub successful.");
> puts("program continues.");
> puts("gosub successful.");
> puts("program ends.");
> return 0;
> }
> but I got something along the lines of (assembler turned back into C
> by hand)
>
> int main()
> {
> int value = 0;
>
> goto begin;
>
> print_continue:
> puts("program continues.");
> value = 0xe;
>
> print_gosub:
> puts("gosub successful.");
>
> begin:
> if (value == 0xc)
> goto print_continue;
> if (value == 0xe)
> goto print_end;
>
> puts("program begins.");
> value = 0xc;
> goto print_gosub;
>
> print_end:
> puts("program ends.");
> return 0;
> }
> I have a hard time imagining that this construct would be more
> efficient than simply printing the output in sequence. Is it the
> switch-case construct causing the compiler to organise the code the
> way it does?

Yes, it looks like the optimizer is having a hard time ironing out all of the
jumping/dispatching. It looks like the generous 10-element stack has been collapsed
into the single element actually used, but that "jump target" variable persists.
A little more unrolling of the loop and it might get closer to the straight ahead
version. But the optimizer doesn't know how close it is, it can't hear the crowd cheering.

Re: gosub.c

<t3qqr3$45l$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21345&group=comp.lang.c#21345

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: gosub.c
Date: Thu, 21 Apr 2022 07:42:11 +0200
Organization: A noiseless patient Spider
Lines: 2
Message-ID: <t3qqr3$45l$1@dont-email.me>
References: <cf49401f-eae2-486d-bcf8-4550e8de5467n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 21 Apr 2022 05:41:55 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="a26fc0b0152e92c59b60997e7f49832d";
logging-data="4277"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19/vp+A672t8FP8y4nA34RGgNDJDiSWck8="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.8.1
Cancel-Lock: sha1:SoQDxJu+1bAx4ec9y/5w2XJwN3s=
In-Reply-To: <cf49401f-eae2-486d-bcf8-4550e8de5467n@googlegroups.com>
Content-Language: de-DE
 by: Bonita Montero - Thu, 21 Apr 2022 05:42 UTC

With C++11 you have lamdas as local functions.
Magnitudes more elegant than you GOSUB-macro-orgy.

What part of... (Well, you know the rest!) (Was: gosub.c)

<t3qs2v$378fb$1@news.xmission.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21346&group=comp.lang.c#21346

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gaze...@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.lang.c
Subject: What part of... (Well, you know the rest!) (Was: gosub.c)
Date: Thu, 21 Apr 2022 06:03:11 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <t3qs2v$378fb$1@news.xmission.com>
References: <cf49401f-eae2-486d-bcf8-4550e8de5467n@googlegroups.com> <t3qqr3$45l$1@dont-email.me>
Injection-Date: Thu, 21 Apr 2022 06:03:11 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="3383787"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Thu, 21 Apr 2022 06:03 UTC

In article <t3qqr3$45l$1@dont-email.me>,
Bonita Montero <Bonita.Montero@gmail.com> wrote:
>With C++11 you have lamdas as local functions.
>Magnitudes more elegant than you GOSUB-macro-orgy.

What part of "C++ is off topic here" do you still not get?

As is Perl, Python, and Fortran (among others).

--
1/20/17: A great day for all those people who are sick of being told
they don't know how to spell "you're" (or "there").

Re: gosub.c

<t3rqi5$fev$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21349&group=comp.lang.c#21349

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: andreyta...@hotmail.com (Andrey Tarasevich)
Newsgroups: comp.lang.c
Subject: Re: gosub.c
Date: Thu, 21 Apr 2022 07:43:15 -0700
Organization: A noiseless patient Spider
Lines: 34
Message-ID: <t3rqi5$fev$1@dont-email.me>
References: <cf49401f-eae2-486d-bcf8-4550e8de5467n@googlegroups.com>
<t3p674$99q$1@nyheter.lysator.liu.se>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 21 Apr 2022 14:43:17 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="1354408e1d2d121911005963ec7052b6";
logging-data="15839"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+atgqVozEAyDKqe1aAeW0P"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.8.1
Cancel-Lock: sha1:3+xMZ3AAPgvIg5g6woculjLGvfQ=
In-Reply-To: <t3p674$99q$1@nyheter.lysator.liu.se>
Content-Language: en-US
 by: Andrey Tarasevich - Thu, 21 Apr 2022 14:43 UTC

> Den 2022-04-12 skrev luser droog <luser.droog@gmail.com>:
> Found this on my disk. I forget where/why it came from but I
> thought it was fun enough to share.
>
>
> % cat gosub.c
> #include <stdio.h>
>
> #define GOSUB(target) do { *stk++ = __LINE__; goto target; case __LINE__: ;} while(0)
> #define RETURN() do{ target = *--stk; goto Goto; } while(0)
>
> int main(){
> int *stk = (int [10]){};
> int target = 0;
> Goto: switch( target ){
> default:
> puts("program begins.");
> GOSUB(test_label);
> puts("program continues.");
> GOSUB(test_label);
> puts("program ends.");
> return 0;
> test_label:
> puts("gosub successful.");
> RETURN();
> }
> }

Just a localized application of the same rather well-known
switch/case-version of Simon Tatham-style coroutine technique.

--
Best regards,
Andrey Tarasevich

Re: What part of... (Well, you know the rest!) (Was: gosub.c)

<t3tdki$rvh$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21375&group=comp.lang.c#21375

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: What part of... (Well, you know the rest!) (Was: gosub.c)
Date: Fri, 22 Apr 2022 07:15:15 +0200
Organization: A noiseless patient Spider
Lines: 11
Message-ID: <t3tdki$rvh$1@dont-email.me>
References: <cf49401f-eae2-486d-bcf8-4550e8de5467n@googlegroups.com>
<t3qqr3$45l$1@dont-email.me> <t3qs2v$378fb$1@news.xmission.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 22 Apr 2022 05:14:58 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="e217344c7ff7905398958bb6d64deeb5";
logging-data="28657"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+NhK1p1EOi8TJX55AJdShgwfjHmMdp8SI="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.8.1
Cancel-Lock: sha1:nrigtznUVCwBZHUo6Tq5v9StccI=
In-Reply-To: <t3qs2v$378fb$1@news.xmission.com>
Content-Language: de-DE
 by: Bonita Montero - Fri, 22 Apr 2022 05:15 UTC

Am 21.04.2022 um 08:03 schrieb Kenny McCormack:
> In article <t3qqr3$45l$1@dont-email.me>,
> Bonita Montero <Bonita.Montero@gmail.com> wrote:
>> With C++11 you have lamdas as local functions.
>> Magnitudes more elegant than you GOSUB-macro-orgy.
>
> What part of "C++ is off topic here" do you still not get?

It's just a recommendation to use a proper language if you wish
sth. like that.

Re: What part of... (Well, you know the rest!) (Was: gosub.c)

<20220422111534.31de4c7bea60921a1525f316@g{oogle}mail.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21376&group=comp.lang.c#21376

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: anton....@g{oogle}mail.com (Anton Shepelev)
Newsgroups: comp.lang.c
Subject: Re: What part of... (Well, you know the rest!) (Was: gosub.c)
Date: Fri, 22 Apr 2022 11:15:34 +0300
Organization: A noiseless patient Spider
Lines: 22
Message-ID: <20220422111534.31de4c7bea60921a1525f316@g{oogle}mail.com>
References: <cf49401f-eae2-486d-bcf8-4550e8de5467n@googlegroups.com>
<t3qqr3$45l$1@dont-email.me>
<t3qs2v$378fb$1@news.xmission.com>
<t3tdki$rvh$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: reader02.eternal-september.org; posting-host="c95adcf60282c4133cd8b3d2bf305876";
logging-data="4621"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+swApDJVeGg9sviaDPyf4VsbY6j3OhZD0="
Cancel-Lock: sha1:JX3wOhdD8T/tIG5IeAOIIe3fk/k=
X-Newsreader: Sylpheed 3.5.0 (GTK+ 2.24.23; i686-pc-mingw32)
 by: Anton Shepelev - Fri, 22 Apr 2022 08:15 UTC

Bonita Montero:

> With C++11 you have lamdas as local functions. Magnitudes
> more elegant than you GOSUB-macro-orgy.

Lambdas, being a functional concept, are alien to a
procedural language. The mixing of functional and procedural
approaches makes a language discordant and more complicated
both to understand and to implement in a complier. C++ is
about a hundred times larger and more complex than C. Since
simplicity is perfection, C++ is inferior to C by the same
factor.

> It's just a recommendation to use a proper language if you
> wish sth. like that.

In this newsgroup the proper language is C, no matter what
the task.

--
() ascii ribbon campaign - against html e-mail
/\ http://preview.tinyurl.com/qcy6mjc [archived]

Re: What part of... (Well, you know the rest!) (Was: gosub.c)

<16c87d26-4712-4b4c-9023-b528f654bf29n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21377&group=comp.lang.c#21377

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:620a:2552:b0:67b:32e2:2400 with SMTP id s18-20020a05620a255200b0067b32e22400mr1913033qko.768.1650618988618;
Fri, 22 Apr 2022 02:16:28 -0700 (PDT)
X-Received: by 2002:a05:6214:23ce:b0:441:8296:a11e with SMTP id
hr14-20020a05621423ce00b004418296a11emr2837723qvb.16.1650618988433; Fri, 22
Apr 2022 02:16:28 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Fri, 22 Apr 2022 02:16:28 -0700 (PDT)
In-Reply-To: <20220422111534.31de4c7bea60921a1525f316@g{oogle}mail.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2a00:23a8:400a:5601:5968:a94b:e247:df83;
posting-account=Dz2zqgkAAADlK5MFu78bw3ab-BRFV4Qn
NNTP-Posting-Host: 2a00:23a8:400a:5601:5968:a94b:e247:df83
References: <cf49401f-eae2-486d-bcf8-4550e8de5467n@googlegroups.com>
<t3qqr3$45l$1@dont-email.me> <t3qs2v$378fb$1@news.xmission.com>
<t3tdki$rvh$1@dont-email.me> <20220422111534.31de4c7bea60921a1525f316@g{oogle}mail.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <16c87d26-4712-4b4c-9023-b528f654bf29n@googlegroups.com>
Subject: Re: What part of... (Well, you know the rest!) (Was: gosub.c)
From: malcolm....@gmail.com (Malcolm McLean)
Injection-Date: Fri, 22 Apr 2022 09:16:28 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 17
 by: Malcolm McLean - Fri, 22 Apr 2022 09:16 UTC

On Friday, 22 April 2022 at 09:15:47 UTC+1, Anton Shepelev wrote:
> Bonita Montero:
> > With C++11 you have lamdas as local functions. Magnitudes
> > more elegant than you GOSUB-macro-orgy.
> Lambdas, being a functional concept, are alien to a
> procedural language. The mixing of functional and procedural
> approaches makes a language discordant and more complicated
> both to understand and to implement in a complier. C++ is
> about a hundred times larger and more complex than C. Since
> simplicity is perfection, C++ is inferior to C by the same
> factor.
>
A trivial little lambda in basically procedural code can make
code easier to read. For instance, if you pass a lambda to std::sort,
you can see at a glace which field is being sorted on. If you pass
a function pointer, it is necessary to scroll to the comparison function.
If you write your own sort routine and embed the comparison code,
then that is many times more difficult to implement and verify.

Re: What part of... (Well, you know the rest!) (Was: gosub.c)

<t3trs9$u4k$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21378&group=comp.lang.c#21378

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: What part of... (Well, you know the rest!) (Was: gosub.c)
Date: Fri, 22 Apr 2022 11:18:18 +0200
Organization: A noiseless patient Spider
Lines: 17
Message-ID: <t3trs9$u4k$1@dont-email.me>
References: <cf49401f-eae2-486d-bcf8-4550e8de5467n@googlegroups.com>
<t3qqr3$45l$1@dont-email.me> <t3qs2v$378fb$1@news.xmission.com>
<t3tdki$rvh$1@dont-email.me>
<20220422111534.31de4c7bea60921a1525f316@g{oogle}mail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 22 Apr 2022 09:18:01 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="e217344c7ff7905398958bb6d64deeb5";
logging-data="30868"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/ObprPsBVio0pZFGCJXme053OpXuLxYpA="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.8.1
Cancel-Lock: sha1:CL8br0qhlLwyWcgU/nFILTSoYt0=
In-Reply-To: <20220422111534.31de4c7bea60921a1525f316@g{oogle}mail.com>
Content-Language: de-DE
 by: Bonita Montero - Fri, 22 Apr 2022 09:18 UTC

Am 22.04.2022 um 10:15 schrieb Anton Shepelev:
> Bonita Montero:
>
>> With C++11 you have lamdas as local functions. Magnitudes
>> more elegant than you GOSUB-macro-orgy.
>
> Lambdas, being a functional concept, are alien to a
> procedural language. The mixing of functional and procedural
> approaches makes a language discordant and more complicated
> both to understand and to implement in a complier. C++ is
> about a hundred times larger and more complex than C. Since
> simplicity is perfection, C++ is inferior to C by the same
> factor.

C++ is magnitutes more superior to C because it's much easier to
realize complex projects with C++. And lambdas make the code also
much more readable and often faster.

Re: What part of... (Well, you know the rest!) (Was: gosub.c)

<t3ts28$if$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21379&group=comp.lang.c#21379

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: What part of... (Well, you know the rest!) (Was: gosub.c)
Date: Fri, 22 Apr 2022 11:21:28 +0200
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <t3ts28$if$1@dont-email.me>
References: <cf49401f-eae2-486d-bcf8-4550e8de5467n@googlegroups.com>
<t3qqr3$45l$1@dont-email.me> <t3qs2v$378fb$1@news.xmission.com>
<t3tdki$rvh$1@dont-email.me>
<20220422111534.31de4c7bea60921a1525f316@g{oogle}mail.com>
<16c87d26-4712-4b4c-9023-b528f654bf29n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 22 Apr 2022 09:21:12 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="e217344c7ff7905398958bb6d64deeb5";
logging-data="591"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Ur9Q3rjQqYoeQwgoyKENkZT9NCmA6J7M="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.8.1
Cancel-Lock: sha1:3hmUZuAK1ZHgw01RHeH+r6amiSs=
In-Reply-To: <16c87d26-4712-4b4c-9023-b528f654bf29n@googlegroups.com>
Content-Language: de-DE
 by: Bonita Montero - Fri, 22 Apr 2022 09:21 UTC

Am 22.04.2022 um 11:16 schrieb Malcolm McLean:
> On Friday, 22 April 2022 at 09:15:47 UTC+1, Anton Shepelev wrote:
>> Bonita Montero:
>>> With C++11 you have lamdas as local functions. Magnitudes
>>> more elegant than you GOSUB-macro-orgy.
>> Lambdas, being a functional concept, are alien to a
>> procedural language. The mixing of functional and procedural
>> approaches makes a language discordant and more complicated
>> both to understand and to implement in a complier. C++ is
>> about a hundred times larger and more complex than C. Since
>> simplicity is perfection, C++ is inferior to C by the same
>> factor.
>>
> A trivial little lambda in basically procedural code can make
> code easier to read. For instance, if you pass a lambda to std::sort,
> you can see at a glace which field is being sorted on. If you pass
> a function pointer, it is necessary to scroll to the comparison function.
> If you write your own sort routine and embed the comparison code,
> then that is many times more difficult to implement and verify.

I not only use lambdas as function objects being passed as a parameter.
I use lambdas when it doesn't make sense to have an external function
because it is only used once to segement the code. And I use lambdas
to have a lot less code to pack redundant code-parts inside a function
inside a lambda. Lambdas are such a giant relief, and with C++20 even
more since you can have templated lambdas.

Re: gosub.c

<a1651b06-f7de-4087-b40b-306df6e2d4cen@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21447&group=comp.lang.c#21447

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:622a:134a:b0:2f3:6a77:d316 with SMTP id w10-20020a05622a134a00b002f36a77d316mr1071219qtk.342.1650850919836;
Sun, 24 Apr 2022 18:41:59 -0700 (PDT)
X-Received: by 2002:a05:620a:4588:b0:69f:1c7d:9793 with SMTP id
bp8-20020a05620a458800b0069f1c7d9793mr7332101qkb.630.1650850919655; Sun, 24
Apr 2022 18:41:59 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Sun, 24 Apr 2022 18:41:59 -0700 (PDT)
In-Reply-To: <t3qqr3$45l$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=24.207.213.87; posting-account=G1KGwgkAAAAyw4z0LxHH0fja6wAbo7Cz
NNTP-Posting-Host: 24.207.213.87
References: <cf49401f-eae2-486d-bcf8-4550e8de5467n@googlegroups.com> <t3qqr3$45l$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <a1651b06-f7de-4087-b40b-306df6e2d4cen@googlegroups.com>
Subject: Re: gosub.c
From: luser.dr...@gmail.com (luser droog)
Injection-Date: Mon, 25 Apr 2022 01:41:59 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 6
 by: luser droog - Mon, 25 Apr 2022 01:41 UTC

On Thursday, April 21, 2022 at 12:42:08 AM UTC-5, Bonita Montero wrote:
> With C++11 you have lamdas as local functions.
> Magnitudes more elegant than you GOSUB-macro-orgy.

It's like literally 2 macros. Two meager lines of code, ok 3 for the harness.
If the result is feature comparable to C++ lambdas, then maybe the takeaway isn't
what you think it is.

Re: What part of... (Well, you know the rest!) (Was: gosub.c)

<8635i18ajw.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21454&group=comp.lang.c#21454

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: What part of... (Well, you know the rest!) (Was: gosub.c)
Date: Mon, 25 Apr 2022 08:09:07 -0700
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <8635i18ajw.fsf@linuxsc.com>
References: <cf49401f-eae2-486d-bcf8-4550e8de5467n@googlegroups.com> <t3qqr3$45l$1@dont-email.me> <t3qs2v$378fb$1@news.xmission.com> <t3tdki$rvh$1@dont-email.me> <20220422111534.31de4c7bea60921a1525f316@g{oogle}mail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="2b2bd3060d7fb14ae545fc6b32585799";
logging-data="17399"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/i36bwIs2VgluksXO58Bs6hfz7UFUQx3s="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:gynXb3KmJxQMQtV/6SVVVyBcfIg=
sha1:yskWXta7KBs9whJWK8F4Gl75AEs=
 by: Tim Rentsch - Mon, 25 Apr 2022 15:09 UTC

Anton Shepelev <anton.txt@g{oogle}mail.com> writes:

> Bonita Montero:
>
>> With C++11 you have lamdas as local functions. Magnitudes
>> more elegant than you GOSUB-macro-orgy.
>
> Lambdas, being a functional concept, are alien to a
> procedural language. The mixing of functional and procedural
> approaches makes a language discordant and more complicated
> both to understand and to implement in a complier. [...]

Even Algol had nested functions.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor