+91 9945200008     support@uttaracomputers.com
LOGIN     REGISTER    

Comments - II audio 36 page 22 - construction of date::today

0
0

Hello Sir,

If we have to use more than one statement to get the current system date, then how do we initialize the static member date::today?

Thanks and regards,

Shreesha

  • You must to post comments
0
0

date::today is a global and hence can be accessed by any module anywhere.  However, since it is declared static inside the class date, it must be constructed and declared at the time of its definition ( which is a must for a static data member of any class ) as follows:

class date {

date ( int xx, int xx, int xx ) {       // example of a constructor

}

static date today;                         // static data member.  This is only a declaration. A definition outside is a must.

 

};

date date::today ( xx, xx, xx );        // The definition of the static member and its construction by invoking the constructor.

 

Now, date::today can be accessed anywhere in any of the modules.

  • svit19@gmail.com
    Thanks for the answer. The problem however is that I don’t know that “xx, xx, xx” to pass as parameter. I would like to make a system call to get the current date and then find xxxxxx and then initialize the different member ints. How do we handle this situation?
  • You must to post comments
0
0

Just for a moment, think of the hardware action taking place when a byte is received at the COM port.  The COM port must have been initialized by system software ( usually in assembly language ) on startup to generate an interrupt on receipt of a byte at the port.  Depending upon the port number, the CPU will pick up the service address as a 4-byte value from a specific address and initiate the interrupt service by implicit invokation of the function at the service address ( regardless of the previous instruction executed by the CPU ), by pushing the address of the next instruction on stack so that the interrupt service function can return the CPU to the exact place where it got interrupted.  The interrupt service routine is most likely an assembly language function since it needs to save all CPU registers before using them.  Once the assembly saving stuff is done, the function can invoke a “C” function with a possible parameter pushed ( which in our case, can be the byte read from the COM port ).  Our Comport class stores the address of the interrupt service function at the correct CPU address.  The “C” function that is invoked by the interrupt service procedure can pick up the first parameter that is the byte read and do what it likes.  In our case, we would like it to invoke a C++ member function of the Host class.  Since the “C” function cannot implicitly push this parameter, it is customary to call the C++ member explicitly using a data of the class type ( , for example,  host.collect ( byte ),  where, host is a data object of the type Host that has been declared and constructed by a statement like     Host host ( xxx, xxx, xxx, .. );

  • svit19@gmail.com
    Thanks Sir. Is this answer written in reply to my previous forum post (Embedded Control – static function to be invoked by dispatcher of interrupt)?
  • mls.shastry@uttaracomputers.com
    Yes; I added it here because you did not post a different question
  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.