public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Pointer to the current function
@ 2021-04-25 21:21 Sergio Costas
  0 siblings, 0 replies; only message in thread
From: Sergio Costas @ 2021-04-25 21:21 UTC (permalink / raw)
  To: gcc

Hello:

I wonder what do you think about a patch to implement getting a pointer 
to the current function. Is it a "no, under no circumstances"? Or it is 
a "maybe, show us the code"?

I'll explain better what I mean: currently there is the statement 
__func__ that returns a string with the name of the current function. 
This allows to print (for example from a macro) which is the current 
function name. Along with __LINE__ it is useful for debugging, among 
other things.

But I miss an statement that allows to have a pointer to the current 
function. Thus putting it in a macro would allow to have a pointer to 
the function where that macro is. It would be very useful for 
coroutines, for example. I've been searching and can't find a simple way 
of doing it. Some people proposes to use __func__ combined with dlsym 
and dlopen, but it is slow and clearly a hack, and forces to use 
-rdynamic, which is not always possible/desirable. Currently I use 
another macro to define the function itself, passing the desired name as 
an argument and creating a variable with a pointer to it, but it is ugly.

Thanks.

-- 
Nos leemos
		         RASTER    (Linux user #228804)
rastersoft@gmail.com                https://www.rastersoft.com


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-04-25 21:21 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-25 21:21 Pointer to the current function Sergio Costas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).