Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Houston, Tranquillity Base here. The Eagle has landed. -- Neil Armstrong


devel / comp.lang.c / Re: Pseudo subroutines with macros

SubjectAuthor
* Pseudo subroutines with macrosAnton Shepelev
+- Re: Pseudo subroutines with macrosAnton Shepelev
`* 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=29604&group=comp.lang.c#29604

  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=29605&group=comp.lang.c#29605

  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

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

  copy mid

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

  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=29622&group=comp.lang.c#29622

  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

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor