使用 g++ 编译器打印 C++ 对象的布局 [英] Print layout of C++ object with g++ compiler

查看:26
本文介绍了使用 g++ 编译器打印 C++ 对象的布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法使用 g++ 编译器或任何其他方式打印 C++ 对象的布局.一个简化的例子(假设 int 占用 4 个字节)

Is there a way to print the layout of a C++ object using the g++ compiler or any other means. A simplified example (assuming int takes 4 bytes)

class A{
  int a;
};

class B:public A{
  int b;
}

所以输出将是

A-
0      4
+  a   +

B-
0      4      8
+ A.a  +  b   +

了解对象的布局会很有用(在我的例子中是虚拟机代码).

It would be useful to understand the layout of objects (in my case virtual machine code).

提前致谢.

问候,扎西尔

推荐答案

看手册页,-fdump-class-hierarchy 可能吗?

这篇关于使用 g++ 编译器打印 C++ 对象的布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆