what will the compiler generate in this case?
Code:class D{ }
what will the compiler generate in this case?
Code:class D{ }
Not a whole lot. Technically, it should create an empty constructor and destructor functions, but seing as those are EMPTY, it may optimize all that away.
When I tried "gcc -S a.c" with your "code" in it, it produces "nothing" [it produces a file, but it's empty aside from some stuff that doesn't actually contain anything - it's just an empty object file].
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Depends on what you mean by "generate." It generates no code (a very dumb compiler might generate some empty functions for constructor and destructor). It does "generate" a class though, which you can use in OTHER code.
Objects of such an empty class actually take up space, contrary to what you might at first assume. Even though class D has no members, it can be instantiated -- and every instance needs a unique address in memory. This means the instances must have some finite (non-zero) size, even though the class doesn't contain anything.
Some compilers can do what is called "empty base optimization" if you derive from an empty class, and the resulting derived class has members. In this case the empty base object doesn't need any space allocated to it.
(since nobody else mentioned it).Code:class D { };