why 1 byte of sizeof empty class

来源:互联网 发布:淘宝模特tim 编辑:程序博客网 时间:2024/06/07 05:51

2011-11-03

1. studying linux kernel any meaning to my life?

2. multithreading, how to assure the real-time AD thread?

3. why 1 byte of sizeof empty class.

Yes, the compiler will generate 1 byte of memory to mark the existence of the class.  This doesn't answer WHY though.  The reason is the language standard states that all classes must have a memory size of at least 1 byte so that the class doesn't occupy the same memory space with another class.  This is to prevent name mangling.  i.e., if I declare a class A {};, the compiler will still generate an entry in its table to something called "A".  If behind that I declare another class, say class B, if A takes 0 bytes of memory, and B's data gets written in the place where A was declared.  In this case, an instantiation of A would take on the properties of B.


one byte will relate to one unique address. is this problem relative to byte allignment?

原创粉丝点击