Is it possible to dynamically define a struct in C

前端 未结 6 1983
暗喜
暗喜 2020-12-14 16:16

I\'m pretty sure this will end up being a really obvious question, and that\'s why I haven\'t found much information on it. Still, I thought it was worth asking :)

B

6条回答
  •  失恋的感觉
    2020-12-14 16:57

    Another theoretical possibility would be to compile some code at run-time using a compiler library such as libtcc.

    While very appealing in theory (it does sound like a self-modifying application – your application would only have to generate C code for your struct and insert it in a template, then ask libtcc to compile it and then call some functions defined in your template to use that struct), this solution will probably not work great in practice. Why ? Well, as of 2016, libtcc (and the whole tcc project) is not very actively developed and there are issues with architectures such as x86_64.

提交回复
热议问题