I want to have a function that returns a function that is called without an argument, even though the original function must be called with an argument. The argument is passed to the first function and will be implicitly used each time a call to the returned function is made.
I am aware of function pointers in C but I don't know if they can be used in such a way. I know how to do this in python as shown in the following sample code :
def foo(some_argument):
print(some_argument)
def register_callback(function, argument):
def new_function():
function(argument)
return new_function
bar = register_callback(foo,"bar")
bar()
From what I read, this way is not possible in C because we can't nest function definitions. Is this possible and if so what would be the proper way to do it?