Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22047

C nested function and promises

$
0
0

For a project I am working on I would like to use GCC nested functions because I would like to have a sort of lambda:

  • I am not interested in supporting other compilers
  • I don't want to access variables from the local context because I don't want to use trampolines

My platform is so far composed by a set of libraries and components and I would like to organise all the business logic on top of it using a combination of nested functions and promises.

My issue is that, as far I understand, the nested function dies within the function context and therefore if I access the function pointer after the function where it has been created returns I may end-up accessing mangled memory.

Is it correct? If yes, is there any alternative? (apart from using C++ :) )

From a very initial testing it looks like it's working when the nested functions are passed around but not sure if it's just because the memory wasn't being overwritten.

In addition, is there any GCC flag that can be used to trigger an error when GCC uses a trampoline for a nested function?

Thanks!


Viewing all articles
Browse latest Browse all 22047

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>