Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Heisenberg may have slept here...


devel / comp.lang.c++ / Pseudo subroutines with macros

SubjectAuthor
* Pseudo subroutines with macrosAnton Shepelev
+* Re: Pseudo subroutines with macrosAnton Shepelev
|`* Re: Pseudo subroutines with macrosPavel
| `* Re: Pseudo subroutines with macrosAnton Shepelev
|  `- Re: Pseudo subroutines with macrosPavel
`* Re: Pseudo subroutines with macrosAlf P. Steinbach
 `- Re: Pseudo subroutines with macrosAnton Shepelev

1
Pseudo subroutines with macros

<20231008152248.df96bddc5a7a2783b2b729af@gmail.moc>

  copy mid

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

  copy link   Newsgroups: comp.lang.c comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: anton....@gmail.moc (Anton Shepelev)
Newsgroups: comp.lang.c,comp.lang.c++
Subject: Pseudo subroutines with macros
Date: Sun, 8 Oct 2023 15:22:48 +0300
Organization: A noiseless patient Spider
Lines: 40
Message-ID: <20231008152248.df96bddc5a7a2783b2b729af@gmail.moc>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="367339d4e143f1bde32c26e30c6cb416";
logging-data="3256089"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18dDFXEbj9Cy8IDxSxW5lq4/DLX38TNJaM="
Cancel-Lock: sha1:ik/5NG2KWXg/oJBo3B8aG54YM/A=
X-Newsreader: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32)
 by: Anton Shepelev - Sun, 8 Oct 2023 12:22 UTC

Hello, all

While comp.lang.c is being choked by spammers, let me ask it
in .c++ as well. Is it possible with the C preprocessor to
generate code patterns of the following form:

if( <expr_1> )
{ ret = 1;
goto PREPROC;
RET_1:
<stmt_1>;
return;
}
if( <expr_2> )
{ ret = 2;
goto PREPROC;
RET_2:
<stmt_2>;
return;
}
... // many lines of intermediate code
switch( ret )
{ case 1: goto RET_1; break;
case 2: goto RET_2; break;
...
}

where the programmer (more or less) only specifies the test
expressions and corresponding statements, e.g.:

#TEST( <expr_1> )
<stmt_1>; // may bec compund, many lines
#TEST( <expr_2> )
<stmt_2>;
#INTERMEDIATE
#TEST_END

--
() ascii ribbon campaign -- against html e-mail
/\ www.asciiribbon.org -- against proprietary attachments

Re: Pseudo subroutines with macros

<20231008154751.c47ae73be66874790d7c99f5@gmail.moc>

  copy mid

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

  copy link   Newsgroups: comp.lang.c comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: anton....@gmail.moc (Anton Shepelev)
Newsgroups: comp.lang.c,comp.lang.c++
Subject: Re: Pseudo subroutines with macros
Date: Sun, 8 Oct 2023 15:47:51 +0300
Organization: A noiseless patient Spider
Lines: 28
Message-ID: <20231008154751.c47ae73be66874790d7c99f5@gmail.moc>
References: <20231008152248.df96bddc5a7a2783b2b729af@gmail.moc>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="367339d4e143f1bde32c26e30c6cb416";
logging-data="3256089"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18AOYd694PQlpvSVMBoqjikbE/TTaYo5g0="
Cancel-Lock: sha1:VrYKWjT0LRYGqSXUc/EpW1+DLY4=
X-Newsreader: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32)
 by: Anton Shepelev - Sun, 8 Oct 2023 12:47 UTC

I wrote:

> if( <expr_1> )
> { ret = 1;
> goto PREPROC;
> RET_1:
> <stmt_1>;
> }
> if( <expr_2> )
> { ret = 2;
> goto PREPROC;
> RET_2:
> <stmt_2>;
>
> }
> ...
> switch( ret )
> { case 1: goto RET_1; break;
> case 2: goto RET_2; break;
> ...
> }

In the code above, label PREPROC is missing. It should be
placed before the `switch' statement.

--
() ascii ribbon campaign -- against html e-mail
/\ www.asciiribbon.org -- against proprietary attachments

Re: Pseudo subroutines with macros

<iDCUM.26171$tnmf.14877@fx09.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx09.iad.POSTED!not-for-mail
Subject: Re: Pseudo subroutines with macros
Newsgroups: comp.lang.c++
References: <20231008152248.df96bddc5a7a2783b2b729af@gmail.moc>
<20231008154751.c47ae73be66874790d7c99f5@gmail.moc>
From: pauldont...@removeyourself.dontspam.yahoo (Pavel)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Firefox/91.0 SeaMonkey/2.53.17.1
MIME-Version: 1.0
In-Reply-To: <20231008154751.c47ae73be66874790d7c99f5@gmail.moc>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 48
Message-ID: <iDCUM.26171$tnmf.14877@fx09.iad>
X-Complaints-To: https://www.astraweb.com/aup
NNTP-Posting-Date: Sun, 08 Oct 2023 18:34:54 UTC
Date: Sun, 8 Oct 2023 14:34:45 -0400
X-Received-Bytes: 1708
 by: Pavel - Sun, 8 Oct 2023 18:34 UTC

Anton Shepelev wrote:
> I wrote:
>
>> if( <expr_1> )
>> { ret = 1;
>> goto PREPROC;
>> RET_1:
>> <stmt_1>;
>> }
>> if( <expr_2> )
>> { ret = 2;
>> goto PREPROC;
>> RET_2:
>> <stmt_2>;
>>
>> }
>> ...
>> switch( ret )
>> { case 1: goto RET_1; break;
>> case 2: goto RET_2; break;
>> ...
>> }
>
> In the code above, label PREPROC is missing. It should be
> placed before the `switch' statement.
>
Straightforward following your description would give something like:

#define STRANGE_IF(n, e, s) if (e) { ret = n; goto PREPROC; RET_##n: s; }
STRANGE_IF(1, a==b, b=c)
STRANGE_IF(2, c==b, c=d)
...
#undef STUPID_IF
....
PREPROC:
switch(ret)
{ #define STRANGE_CASE(n) case n: goto RET_##n; break;
STRANGE_CASE(1)
STRANGE_CASE(2)
...
#endif STRANGE_CASE
}

Is this what you are looking to do?

HTH
-Pavel

Re: Pseudo subroutines with macros

<20231008221036.3e999e41d056d5229c147e6a@gmail.moc>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!paganini.bofh.team!not-for-mail
From: anton....@gmail.moc (Anton Shepelev)
Newsgroups: comp.lang.c++
Subject: Re: Pseudo subroutines with macros
Date: Sun, 8 Oct 2023 22:10:36 +0300
Organization: To protect and to server
Message-ID: <20231008221036.3e999e41d056d5229c147e6a@gmail.moc>
References: <20231008152248.df96bddc5a7a2783b2b729af@gmail.moc>
<20231008154751.c47ae73be66874790d7c99f5@gmail.moc>
<iDCUM.26171$tnmf.14877@fx09.iad>
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: paganini.bofh.team; logging-data="1838671"; posting-host="ok5CnZ1oci+WG7h7xAEZ1A.user.paganini.bofh.team"; mail-complaints-to="usenet@bofh.team"; posting-account="9dIQLXBM7WM9KzA+yjdR4A";
Cancel-Lock: sha256:YKqAWEKzI2HipzZDCwVcgEcvB3/kJ8pvjBUeW53eMJo=
X-Notice: Filtered by postfilter v. 0.9.3
X-Newsreader: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32)
 by: Anton Shepelev - Sun, 8 Oct 2023 19:10 UTC

Pavel:

> Straightforward following your description would give something like:
>
> #define STRANGE_IF(n, e, s) if (e) { ret = n; goto PREPROC; RET_##n: s; }
> STRANGE_IF(1, a==b, b=c)
> STRANGE_IF(2, c==b, c=d)
> ..
> #undef STUPID_IF
> ...
> PREPROC:
> switch(ret)
> {
> #define STRANGE_CASE(n) case n: goto RET_##n; break;
> STRANGE_CASE(1)
> STRANGE_CASE(2)
> ..
> #endif STRANGE_CASE
> }
>
> Is this what you are looking to do?

Yes, except I hoped for a less redundant way to specify this
code. You manually count from 1..n twice. If a better
version is impossible in C, then I think I will be going
that way.

Say! You forgot to rename into STRAGE one occurance
STUPID :-) Thank you, though.

Did you intentionally drop comp.lang.c ?

Re: Pseudo subroutines with macros

<ufv5ji$3alna$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: alf.p.st...@gmail.com (Alf P. Steinbach)
Newsgroups: comp.lang.c,comp.lang.c++
Subject: Re: Pseudo subroutines with macros
Date: Sun, 8 Oct 2023 23:05:54 +0200
Organization: A noiseless patient Spider
Lines: 44
Message-ID: <ufv5ji$3alna$1@dont-email.me>
References: <20231008152248.df96bddc5a7a2783b2b729af@gmail.moc>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 8 Oct 2023 21:05:54 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="f221e8663d34f494cb489bf7d16f60e0";
logging-data="3495658"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+ct54FgwGaZvGkBAl84JNz"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:kI5BTRQufz7HQSnQwYMUvlsxgPk=
Content-Language: en-US
In-Reply-To: <20231008152248.df96bddc5a7a2783b2b729af@gmail.moc>
 by: Alf P. Steinbach - Sun, 8 Oct 2023 21:05 UTC

On 2023-10-08 2:22 PM, Anton Shepelev wrote:
> Hello, all
>
> While comp.lang.c is being choked by spammers, let me ask it
> in .c++ as well. Is it possible with the C preprocessor to
> generate code patterns of the following form:
>
> if( <expr_1> )
> { ret = 1;
> goto PREPROC;
> RET_1:
> <stmt_1>;
> return;
> }
> if( <expr_2> )
> { ret = 2;
> goto PREPROC;
> RET_2:
> <stmt_2>;
> return;
> }
> ... // many lines of intermediate code
PREPROC:
> switch( ret )
> { case 1: goto RET_1; break;
> case 2: goto RET_2; break;
> ...
> }
>
> where the programmer (more or less) only specifies the test
> expressions and corresponding statements, e.g.:
>
> #TEST( <expr_1> )
> <stmt_1>; // may bec compund, many lines
> #TEST( <expr_2> )
> <stmt_2>;
> #INTERMEDIATE
> #TEST_END
>

What's the purpose of the jumps to the `switch` and back? It does nothing.

- Alf

Re: Pseudo subroutines with macros

<20231009012503.243779869849c6bb292a8bc0@gmail.moc>

  copy mid

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

  copy link   Newsgroups: comp.lang.c comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: anton....@gmail.moc (Anton Shepelev)
Newsgroups: comp.lang.c,comp.lang.c++
Subject: Re: Pseudo subroutines with macros
Date: Mon, 9 Oct 2023 01:25:03 +0300
Organization: A noiseless patient Spider
Lines: 37
Message-ID: <20231009012503.243779869849c6bb292a8bc0@gmail.moc>
References: <20231008152248.df96bddc5a7a2783b2b729af@gmail.moc>
<ufv5ji$3alna$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="b412e11e36117f345904fd0fc803ee89";
logging-data="3536236"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+13hoaSu9ce5q6GYmZpDxsZk3uKAxnq+Y="
Cancel-Lock: sha1:AK5/YMuz6rcb3fOBE+JZv+srX2Y=
X-Newsreader: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32)
 by: Anton Shepelev - Sun, 8 Oct 2023 22:25 UTC

Alf P. Steinbach:

> What's the purpose of the jumps to the `switch` and back?
> It does nothing.

Shall I quote my entire code from the previous article, or
may I count on everybody's smart newsreaders that can step
up the thread at a single keystroke?

To answer your question, I was thinking of implementing a
state-machine, where the entire cycle or tick (entry, exit,
transition) is located in a single function and executed in
a single invocation of it. The transition-handling code is
specific for each transition leading out of the current
state. The exit-handling code is common to the state and
must be executed /before/ the transition-handling code, but
/only/ if a transition occurs, therefore:

if( trans_cond_1 )
{ ret = 1; /* a transition must be performed */
goto EXIT; /* but we must exit current state first */
TRANS_1:
/* transition-handler here */
return;
}
...
return; /* no transition */
switch( ret )
{ case 1: goto TRANS_1; break;
...
}

See what I mean?

--
() ascii ribbon campaign -- against html e-mail
/\ www.asciiribbon.org -- against proprietary attachments

Re: Pseudo subroutines with macros

<t9oVM.36596$rbid.12945@fx18.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!1.us.feeder.erje.net!feeder.erje.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx18.iad.POSTED!not-for-mail
Subject: Re: Pseudo subroutines with macros
Newsgroups: comp.lang.c++
References: <20231008152248.df96bddc5a7a2783b2b729af@gmail.moc>
<20231008154751.c47ae73be66874790d7c99f5@gmail.moc>
<iDCUM.26171$tnmf.14877@fx09.iad>
<20231008221036.3e999e41d056d5229c147e6a@gmail.moc>
From: pauldont...@removeyourself.dontspam.yahoo (Pavel)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Firefox/91.0 SeaMonkey/2.53.17.1
MIME-Version: 1.0
In-Reply-To: <20231008221036.3e999e41d056d5229c147e6a@gmail.moc>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 54
Message-ID: <t9oVM.36596$rbid.12945@fx18.iad>
X-Complaints-To: https://www.astraweb.com/aup
NNTP-Posting-Date: Wed, 11 Oct 2023 02:56:25 UTC
Date: Tue, 10 Oct 2023 22:56:19 -0400
X-Received-Bytes: 2451
 by: Pavel - Wed, 11 Oct 2023 02:56 UTC

Anton Shepelev wrote:
> Pavel:
>
>> Straightforward following your description would give something like:
>>
>> #define STRANGE_IF(n, e, s) if (e) { ret = n; goto PREPROC; RET_##n: s; }
>> STRANGE_IF(1, a==b, b=c)
>> STRANGE_IF(2, c==b, c=d)
>> ..
>> #undef STUPID_IF
>> ...
>> PREPROC:
>> switch(ret)
>> {
>> #define STRANGE_CASE(n) case n: goto RET_##n; break;
>> STRANGE_CASE(1)
>> STRANGE_CASE(2)
>> ..
>> #endif STRANGE_CASE
>> }
>>
>> Is this what you are looking to do?
>
> Yes, except I hoped for a less redundant way to specify this
> code. You manually count from 1..n twice. If a better
> version is impossible in C,
I saw some clever preprocessor tricks that avoid repetition in different
situations but I find these difficult to read so I try to avoid (in C++
I usually can). If you are determined to solve your problem with a
clever macro, take a look at

https://codereview.stackexchange.com/questions/237410/macro-to-generate-an-enum-and-an-array-of-strings

Vaguely speaking, this technique allows "defining many aspects of a
thing in one place" given a list of "things". That is, every one of many
"things" is mentioned only once. Maybe you can figure out how to use it
to your advantage.

HTH

> then I think I will be going
> that way.
>
> Say! You forgot to rename into STRAGE one occurance
> STUPID :-)
:-)

> Thank you, though.
You are welcome.

>
> Did you intentionally drop comp.lang.c ?
Yes. I guessed those spammers you mentioned select target thread by
activity, so decided to lay low.


devel / comp.lang.c++ / Pseudo subroutines with macros

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor