what will compiler generate

This is a discussion on what will compiler generate within the C++ Programming forums, part of the General Programming Boards category; what will the compiler generate in this case? Code: class D{ }...

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    9

    what will compiler generate

    what will the compiler generate in this case?

    Code:
    class D{
    }

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

  3. #3
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,238
    Quote Originally Posted by rnx40401 View Post
    what will the compiler generate in this case?

    Code:
    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
    Posts
    835
    Code:
    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, 05:42 AM
  4. how to call a compiler?
    By castlelight in forum C Programming
    Replies: 3
    Last Post: 11-22-2005, 10:28 AM
  5. Help With finding a compiler
    By macman in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 04-15-2005, 08:15 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21