Programmatic way to get variable name in C?

前端 未结 10 1818
广开言路
广开言路 2020-11-29 23:08

I am developing a tool to dump data from variables. I need to dump the variable name, and also the values.

My solution: Store variable name as a string, and print th

10条回答
  •  无人及你
    2020-11-29 23:48

    People often want programs to self-introspect (or "reflect" in current jargon). But most programming languages offer little (e.g., Java) or none (C) capability to reflect on all the details of a program (variable names, function names, types, expression structures, etc.).

    There's a way to do this for all languages: step outside the language, and use a tool that is designed to extract that information from the language. A class of tool that can do this is called a program transformation system.

    See this SO answer for a discussion of how to "get variable names" and print values using a program transformation system: Trace changes to variables automatically

提交回复
热议问题