I'm afraid to ask this on SO because all I can get is down-vote so I ask it here.*
Question:
Does C/C++ compiler (e.g the popular "gcc") with OO concepts allocates/creates all data member if other data member are not in use?
/*************************************
* code for example: *
**************************************
typedef std::size_t Int;
class Rectangle
{
public:
Int x;
Int y;
Int width;
Int height;
Int border_top;
Int border_right;
Int border_bottom;
Int border_left;
}
//suppose I instantiate many of this class then call "some" data members
Rectangle rect1, rect2, ...;
rect1.x = 0;
rect1.y = 0;
//rect1.other_member arent called on the entire code;
rect2.width = 640;
rect2.height = 480;
//rect2.other_member arent called on the entire code;
/*************************************
* end of code *
**************************************
Does compiler allocates or reserved memory space from the data member the are not in use?
I think, compilers are smart enough to determine which data member are in use of that object and which are not. So is there a reason (WHY and WHY NOT) they (DO or DO NOT) allocate space those resources?
--------------------------------------
Also is there a site that discusses what does all the compiler is doing behind every programming concepts/paradigm it encountered?
Feel free to correct me If my assumptions are wrong :)
Thanks!
Sorry for I'm bad at explaining things.