Search code examples
cfunctionargumentsintrospection

Is introspection on a function's arguments in C possible?


For example, in Python I can use getargspec from inspect to access a function's arguments in the follow way:

>>> def test(a,b,c):
...     return a*b*c
...
>>> getargspec(test)
ArgSpec(args=['a', 'b', 'c'], varargs=None, keywords=None, defaults=None)

Is this possible to do in C at all? More specifically I am only interested in the arguments' names, I don't particularly care about their types.


Solution

  • The language doesn't include anything along this line at all.

    Depending on the implementation, there's a pretty fair chance that if you want this badly enough, you can get at it. To do so, you'll typically have to compile with debugging information enabled, and use code specific to a precise combination of compiler and platform to do it. Most compilers do support creating and accessing debugging information that would include the names of the parameters to a function -- but code to do it will not be portable (and in many cases, it'll also be pretty ugly).