473,396 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How does aCC compiler react to object creation

3
I need to know what exactly the aCC compiler or any other compiler does when it encounters an object creation as in line # 9 :
Expand|Select|Wrap|Line Numbers
  1. 1    class A
  2. 2    { 
  3. 3       int i;
  4. 4       public:
  5. 5        A(){ i=0;}
  6. 6     };
  7. 7   int main()
  8. 8   { 
  9. 9    A a1;
  10. 10  return 0;
  11. 11  }
  12.  
To be more clear, I would like to know the series of actions the COMPILER does to execute line # 9. Does it embed the code of the constructor since constructor is inline?
Nov 13 '07 #1
4 1566
weaknessforcats
9,208 Expert Mod 8TB
Yes, it does. It has to. Otherwise, there would be multuple constructor functions created every time you included your header somewhere else.

Why is the constructor inline?? C++ is not Java. By exposing your constructor definition, the users have to recompile and relink should you change it. By keeping the definition in another soruce file, the users need only relink.
Nov 13 '07 #2
bmsce
3
Yes, it does. It has to. Otherwise, there would be multuple constructor functions created every time you included your header somewhere else.

Why is the constructor inline?? C++ is not Java. By exposing your constructor definition, the users have to recompile and relink should you change it. By keeping the definition in another soruce file, the users need only relink.
Thanks for your response weaknessforcats. But my worry is about the things the compiler does when it has to execute line # 9. Here are few queries. Pl answer them:
1) Does compiler allocate memory for that object a1 and initialize it? OR
2) Does it only put the object a1 in its symbol table without initializing it?

I am little curious to know as to what are the things that happen during compilation in line # 9.
Nov 14 '07 #3
weaknessforcats
9,208 Expert Mod 8TB
The steps are:

1) memory for the object is allocated
2) the constructors for each data member are called
3) the contructor for the object itself is called

Please note that if members of A are class objects, then their constructors are called and if and of those members have class members then those constructors are called also ad infinitum until you arrive at a class with nothing but built-in types for data members.
Nov 14 '07 #4
bmsce
3
The steps are:

1) memory for the object is allocated
2) the constructors for each data member are called
3) the contructor for the object itself is called

Please note that if members of A are class objects, then their constructors are called and if and of those members have class members then those constructors are called also ad infinitum until you arrive at a class with nothing but built-in types for data members.
I got it!! Thanks a ton.
Nov 15 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Ryan Mitchley | last post by:
Hi all I have code for an object factory, heavily based on an article by Jim Hyslop (although I've made minor modifications). The factory was working fine using g++, but since switching to the...
2
by: Jan Nielsen | last post by:
Hi I have a form with some comboboxes My problem is that they don't react on my doubleclick event. I doubleclick in the textbox part of the combo. And nothing happens. They react on...
3
by: Richard Lewis Haggard | last post by:
We are having a lot of trouble with problems relating to failures relating to 'The located assembly's manifest definition with name 'xxx' does not match the assembly reference" but none of us here...
17
by: christophe.chazeau | last post by:
Hi, I have a problem with a really simple chunk of code which should work but does obviously does not. This chunk of code is just a POC aimed at finding a bug in a larger project in which the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.