获取 c++ 的字节大小以字符串形式给出的结构
我有以下问题。我得到了一根绳子。该字符串代表一个有效的 C++ 结构。
我需要找出获取此结构的字节大小的最快方法。
对我来说最明显的方法是:
将结构写入文件并将该文件转换为将大小写入文件的脚本,从系统调用编译器,编译文件,运行可执行文件,解析文件。
这是荒谬的,必须有更好的方法。
我听说过 GCC 的 JITC 库,这可能是更好的方法。但由于我不需要完整的编译,可能有更简单的方法吗?
该结构的表示方式与本机 C++ 代码中的表示方式相同,即我有这个字符串
“结构MySstruct { int 字段1; 无效*字段2; 短场3; };"
将是字符串的内容。
I have the following problem. I am given a string. This string represents a valid c++ struct.
I need to figure out the fastest way to get the size in bytes of this struct.
The most obvious approach to me is:
Write struct to a file and turn that file into a script that writes the size to a file, call a compiler from the system, compile the file, run the executable, parse the file.
This is absurd, there has to be a better way.
I have heard about GCC's JITC library, that might be a better approach. But since I don;t need full blown compilation there might be a simpler way?
The struct is represented as it would in native c++ code, i.e. I have this string
"struct MySstruct {
int field1;
void* field2;
short field3;
};"
Would be the content of the string.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论