Sunday, October 8, 2023

Digest for comp.lang.c++@googlegroups.com - 4 updates in 2 topics

"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Oct 08 12:31PM -0700

On 10/8/2023 4:22 AM, candycanearter07 wrote:
 
> What if you typedef'd the function pointer?
 
> Also, you could probably get away with it by just setting it to a void
> pointer and casting the return value to the function pointer.
 
Not sure if that's allowed. A function pointer cast to a void pointer,
which in turn is cast back to a function pointer is undefined? What am I
forgetting here?
Keith Thompson <Keith.S.Thompson+u@gmail.com>: Oct 08 03:31PM -0700

>> so an explicit conversion is seem inevitable.
 
> It mayn't be supported in standard C, but it's a common extension—in fact,
> POSIX _requires_ it in order for the dlsym subroutine to work.
 
The POSIX requirement is limited to values returned by dlsym().
 
https://pubs.opengroup.org/onlinepubs/9699919799/functions/dlsym.html
 
> The return value from dlsym(), cast to a pointer to the type of the
> named symbol, can be used to call (in the case of a function) or access
> the contents of (in the case of a data object) the named symbol.
 
An implementation could satisfy that requirement without supporting
void* to function pointer conversions in general.
 
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Will write code for food.
void Void(void) { Void(); } /* The recursive call of the void */
"Alf P. Steinbach" <alf.p.steinbach@gmail.com>: Oct 08 11:05PM +0200

On 2023-10-08 2:22 PM, Anton Shepelev wrote:
> return;
> }
> ... // many lines of intermediate code
PREPROC:
> <stmt_2>;
> #INTERMEDIATE
> #TEST_END
 
What's the purpose of the jumps to the `switch` and back? It does nothing.
 
- Alf
Anton Shepelev <anton.txt@gmail.moc>: Oct 09 01:25AM +0300

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
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

No comments: