Sunday, October 8, 2023

Digest for comp.lang.c++@googlegroups.com - 25 updates in 10 topics

Anton Shepelev <anton.txt@gmail.moc>: Oct 08 03:22PM +0300

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
Anton Shepelev <anton.txt@gmail.moc>: Oct 08 03:47PM +0300

I wrote:
 
> 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
Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo>: Oct 08 02:34PM -0400

Anton Shepelev wrote:
>> }
 
> 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)
..

No comments: