473,387 Members | 1,721 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,387 software developers and data experts.

which kinds of constructors may be applied during compile time as optimization.

8
take two following classes and their constructors as samples:

Expand|Select|Wrap|Line Numbers
  1. class One{
  2.  public:
  3.   One(int a,int b):adad1(a),adad2(b){}
  4.  private:
  5.   int adad1;
  6.   int adad2;
  7. };
  8. class Two{
  9.  public:
  10.   Two(int input[]){
  11.    for (int i=0;i<10;i++)
  12.     araye[i]=input[i];
  13.   }
  14.  private:
  15.   int araye[10];
  16. };
considering objects with static storage duration, I think first constructor can be applied during compile time due to its free function body that allows it to be converted to a constant expression in some cases as an optimization, but I have doubt about second one. anyway is there any rule specifying which kinds of constructors can be applied during compile time ?
Jul 21 '10 #1
2 1496
weaknessforcats
9,208 Expert Mod 8TB
First, constructors are not applied at compile time. They are called only at run time.

Second, what does static have to do with anything?
Each of these classes can be used to create static objects.

Third, what does const have to do with anything?
Each of these classes can be used to create const objects.

Are you by any chance thinking of const data members rather than const objects?
Jul 21 '10 #2
Pooria
8
@weaknessforcats
First, constructors are not applied at compile time. They are called only at run time.

Second, what does static have to do with anything?
Each of these classes can be used to create static objects.

An implementation is permitted to perform the initialization of an object of namespace scope with static storage duration as a static initialization even if such initialization is not required to be done statically, provided that

* the dynamic version of the initialization does not change the value of any other object of namespace scope with static storage duration prior to its initialization, and
* the static version of the initialization produces the same value in the initialized object as would be produced by the dynamic initialization if all objects not required to be initialized statically were initialized dynamically.


Third, what does const have to do with anything?
Each of these classes can be used to create const objects.

Are you by any chance thinking of const data members rather than const objects?
please go here and take a look around.
Jul 21 '10 #3

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

Similar topics

17
by: newbiecpp | last post by:
I have hard time to understand run-time environment. Let assume that I have a program that has a simple variable alpha. When this variable is statically allocated, the compiler can use the...
7
by: Samee Zahur | last post by:
Hello, The other day I was rather shocked to find that I couldn't find a good use for runtime polymorphism! Let me explain this a bit further before you get shocked. Any function that I could...
1
by: yccheok | last post by:
Hi, consider the following bug at #include <stdio.h> class Drink { public: Drink( char *name_ ) : name( name_ ) {} char *name; char & get(int i) { return name; } };
5
by: Carmine Cairo | last post by:
Hi, I'm working on a project and today I've note a little problem during the compile fase. Here a little piece of code: // 1st version welldone = 0; size = p->getSize(); backbone = new...
2
by: Glen | last post by:
I'm working on a custom assembly and I'm trying to figure out the best approach to handling known constraints within the assembly, once compiled, to alert the developer at compile time of a...
13
by: Adam Blair | last post by:
Is it possible to bind a switch statement to an Enum such that a compile-time error is raised if not all values within the Enum are handled in the switch statement? I realise you can use default:...
5
by: Michael | last post by:
i experience slower compile times with VC++ 2003 compared to VC+6.0. Anyone experiencing the same? Should that be expected? This ineed matters, when total compilation time is > 1h and you have to...
7
by: dc | last post by:
Can anybody think of a situation where virtual function's address resolution/ something related to virtual is done at compile time
3
by: Christof Warlich | last post by:
Hi all, in the following example, Index<unsigned int x>::value allows to calculate the "rounded up" index from any "increasing" value during compile time. Unfortunately, the definition of the...
27
by: CodeMonk3y | last post by:
gotta question on sizeof keyword does the sizeof keyword calcuates the size at compile time or run time ?? -- Posted on news://freenews.netfront.net - Complaints to news@netfront.net --
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.