|
-
December 13th, 2006, 02:46 AM
#1
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
-
December 13th, 2006, 02:59 AM
#2
Re: when is object created ???
An object is created at runtime.
 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
-
December 13th, 2006, 05:32 AM
#3
Re: when is object created ???
 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?
Can you help me with my homework assignment?, Before you post!, Use code tags, How to post!, Codeguru technical FAQs, C++ FAQ Lite, Stroustrup: C++ Style and Technique FAQ, Guru of the Week, Comeau C and C++ FAQs, Comeau C++ Templates FAQs, CUJ @ DDJ, Spam threshold
My Blogs : Learning C++ is fun | Abnegator's reflections
Open Threads : C++ Aha! Moments | Nature of work in C++?
-
December 13th, 2006, 03:21 PM
#4
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
-
December 14th, 2006, 05:48 AM
#5
Re: when is object created ???
 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()!
-
December 14th, 2006, 10:53 AM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|