On Monday 15 April 2002 03:44, Martin Janssen wrote:
> Hi Robert,
>
> sc_time_stamp() returns a sc_time value. This type has no
> implicit conversion to double, hence
>
> printf( "... %d ...", sc_time_stamp() );
>
> doesn't work and may have caused the unknown exception.
You need to be careful of the format specifier used in the call to printf()
too (if you decide to use printf() rather than an ostream). The %d specifier
is inappropriate if you are actually trying to output a double (as in the
case of sc_simulation_time() or sc_time_stamp().to_double()) as it is
intended to output values of type int. For values of type double, %f is
probably what you want.
Most compilers won't give warnings or errors for this, as ISO standard C and
C++ specify no mechanism by which this sort of thing might be detected. gcc
(when supplied with appropriate declarations of the functions in question) is
the notable exception to this generalization.
Regards
M.Beach
> Try one of the following:
>
> // in terms of the time resolution
> printf( "... %d ...", sc_time_stamp().to_double() );
> // in seconds
> printf( "... %d ...", sc_time_stamp().to_seconds() );
> // in terms of the default time unit
> printf( "... %d ...", sc_simulation_time() );
> // as a string
> printf( "... %s ...", sc_time_stamp().to_string().c_str() );
>
> // my recommendation:
> cout << "global time: " << sc_time_stamp() << endl;
>
> Martin
> -oo-
>
> yigui Luo wrote:
> > Hi , all:
> > In the following little programme:
> > /*************************************************/
> > #include "systemc.h"
> > #include "stdio.h"
> > #include "stdlib.h"
> > struct ff:sc_module{
> > sc_in<bool> p1;
> > sc_in_clk clk;
> > sc_out<bool> p2;
> >
> > void mydisplay();
> >
> > SC_CTOR(ff){
> > SC_CTHREAD(mydisplay,clk.pos());
> > }
> > };
> >
> > void ff::mydisplay(){
> > while(true){
> > wait();
> > printf("global_time:%d ",sc_time_stamp()); }
> > }
> >
> >
> > int sc_main(int argc,char* argv[]){
> > sc_signal<bool> pp1;
> > sc_signal<bool> pp2;
> > sc_clock clk("clk",1,0.5,0,true);
> >
> > ff ff1("ff1");
> > ff1.p1(pp1);
> > ff1.clk(clk);
> > ff1.p2(pp2);
> > sc_start(clk, -1);
> > return 1;
> > }
> > /**********************************************/
> > there is no error on compiling and link to exe,but
> > when execution the tt2.exe,tell me "UNKOWN
> > UNEXPECTATION ERROR",why,can tell me ?
> > Thanks!
> >
> >
> > Robert
> >
> >
> > _________________________________________________________
> > Do You Yahoo!?
> > 30 ÕÅÃâ·ÑÊÀ½ç±ÇòƱ 7 ÌìËÍÍ꣡ÓÐÖÖÄã¾Í¿ìÀ´ÇÀ£¡
> > http://cn.promo.yahoo.com/49/
> >
> > _______________________________________________
> > Systemc-forum mailing list
> > Systemc-forum@xxxxxxxxxxxxxxxxxxx
> > https://server2.systemc.org/mailman/listinfo/systemc-forum
>
> _______________________________________________
> Systemc-forum mailing list
> Systemc-forum@xxxxxxxxxxxxxxxxxxx
> https://server2.systemc.org/mailman/listinfo/systemc-forum
|