Thread: what will compiler generate

  1. #1
    Registered User
    Join Date
    Oct 2007

    what will compiler generate

    what will the compiler generate in this case?

    class D{

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    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].

    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.

  3. #3
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Portland, OR
    Quote Originally Posted by rnx40401 View Post
    what will the compiler generate in this case?

    class D{
    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.

  4. #4
    Registered User
    Join Date
    Sep 2006
    class D {
    (since nobody else mentioned it).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiler Paths...
    By Cobra in forum C++ Programming
    Replies: 5
    Last Post: 09-26-2006, 04:04 AM
  2. C Compiler and stuff
    By pal1ndr0me in forum C Programming
    Replies: 10
    Last Post: 07-21-2006, 11:07 AM
  3. I can't get this new compiler to work.
    By Loduwijk in forum C++ Programming
    Replies: 7
    Last Post: 03-29-2006, 06:42 AM
  4. how to call a compiler?
    By castlelight in forum C Programming
    Replies: 3
    Last Post: 11-22-2005, 11:28 AM
  5. Help With finding a compiler
    By macman in forum A Brief History of
    Replies: 4
    Last Post: 04-15-2005, 08:15 AM