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
Printable View
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
An object is created at runtime.
Yes you can say so.Quote:
Originally Posted by sundar svb
Take a look at this; http://www.parashift.com/c++-faq-lite/ctors.html
Laitinen
Again, I would want you to reply with the answers to the following questions:Quote:
Originally Posted by sundar_svb
1. What does compile time mean?
2. And then what would object creation at compile time mean?
3. What does runtime mean?
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).
Which post??? I don't see any post from dcjr84 on this thread.Quote:
Originally Posted by TheCPUWizard
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.Quote:
Static Objects (in standard C++) are created at runtime, but at some point prior to main() beginning execution.
Anyway, all objects: static, automatic, on free-store and constructed with any mean that the language gives, begin their lifetime at runtime.
Assuming object creation is the process of allocating physical space and calling constructor for an object.Quote:
The compiler *never* creates objects. The compiler is responsible for turning your C++ source file into machine code (or sometimes an intermediate language).
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. :eek: (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.
I deleted my post.Quote:
Which post??? I don't see any post from dcjr84 on this thread.
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.