CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2006
    Posts
    9

    Thumbs up when is object created ???

    Hi...
    when object is created ..is it at compile time or runtime ???
    can we say => it's a runtime instance of a class ????



    Regards,
    Sundar.G

  2. #2
    Join Date
    May 2006
    Location
    Norway
    Posts
    1,709

    Re: when is object created ???

    An object is created at runtime.

    Quote Originally Posted by sundar svb
    can we say => it's a runtime instance of a class ????
    Yes you can say so.


    Take a look at this; http://www.parashift.com/c++-faq-lite/ctors.html

    Laitinen

  3. #3
    Join Date
    Feb 2005
    Location
    "The Capital"
    Posts
    5,306

    Re: when is object created ???

    Quote Originally Posted by sundar_svb
    when object is created ..is it at compile time or runtime ??? can we say => it's a runtime instance of a class ????
    Again, I would want you to reply with the answers to the following questions:

    1. What does compile time mean?
    2. And then what would object creation at compile time mean?
    3. What does runtime mean?

  4. #4
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: when is object created ???

    DCJR84,
    Your post is about as wrong as something can be.....

    Static Objects (in standard C++) are created at runtime, but at some point prior to main() beginning execution.

    The compiler *never* creates objects. The compiler is responsible for turning your C++ source file into machine code (or sometimes an intermediate language).
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  5. #5
    Join Date
    Feb 2005
    Location
    Normandy in France
    Posts
    4,590

    Re: when is object created ???

    Quote Originally Posted by TheCPUWizard
    DCJR84,
    Your post is about as wrong as something can be.....
    Which post??? I don't see any post from dcjr84 on this thread.

    Static Objects (in standard C++) are created at runtime, but at some point prior to main() beginning execution.
    Yes, but I think that the question is even more general... It's a question about all objects, including but not limited to, static objects.
    Anyway, all objects: static, automatic, on free-store and constructed with any mean that the language gives, begin their lifetime at runtime.

    The compiler *never* creates objects. The compiler is responsible for turning your C++ source file into machine code (or sometimes an intermediate language).
    Assuming object creation is the process of allocating physical space and calling constructor for an object.

    It is not clear whether a typical static-storage internal-linkage const integral (or of sufficiently simple class type) object whose address if never used, is "created" at runtime (not to mean that it's created at compile-time... it's not really created by an identifiable mean) when compiled with optimizing compilers that put immediate literal in assembly code.
    In fact, here, we may say that the variable is created by the OS at startup time (when space is allocated for the code).
    Or, we may say that the variable is never created.
    And, if the data is put in a shared data section, the storage for the object will be effectively created before program startup of the second instance when two instances of an application are launched...
    It may even be possible to imagine a shared section physically allocated before compile time. (feel free to ask for details).

    On the other hand, if we think with a more abstract model, abstracting optimizations details as far as they don't modify the execution on this abstract model; that is, if we think with the abstract machine of the standard: We can say that objects are created (i.e. their lifetime begins) during execution, and not during any phase of the translation.

    If we rename execution to runtime and translation to compilation, we can say that objects are created at runtime.
    Last edited by SuperKoko; December 14th, 2006 at 06:09 AM.
    "inherit to be reused by code that uses the base class, not to reuse base class code", Sutter and Alexandrescu, C++ Coding Standards.
    Club of lovers of the C++ typecasts cute syntax: Only recorded member.

    Out of memory happens! Handle it properly!
    Say no to g_new()!

  6. #6
    Join Date
    Sep 2005
    Location
    United States
    Posts
    799

    Re: when is object created ???

    Which post??? I don't see any post from dcjr84 on this thread.
    I deleted my post.

    I was half asleep on the keyboard when I made it.

    Later when I saw what I had typed, I decided it was the most absurd post I had ever made.

    Still not sure of the reasoning behind it, or exactly what I said, but it was very dumb I can assure you.
    Please rate my post if you felt it was helpful

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured