SysTime in a Struct

Ali Çehreli acehreli at yahoo.com
Thu Mar 1 08:20:47 PST 2012


On 03/01/2012 06:15 AM, albatroz wrote:
 > Hi,
 >
 > I have defined this struct
 > struct preEv {
 > string edate; //010112
 > string etime; //00:00:00
 > string etext; //
 > SysTime esystime;

That is a member of this type.

 > this (this) {
 > SysTime esystime = SysTime(DateTime(

That is a separate local variable within this(this). Also, this(this) is 
the postblit (similar to a copy constructor). Is that what you want to 
define?

I think you want to simply do this anyway:

    esystime =

or this:

    this.esystime =

 > Clock.currTime.year,
 > to!int(this.edate[2..4]),
 > to!int(this.edate[0..2]),
 > to!int(etime[0..2]),
 > to!int(etime[3..5]),
 > to!int(etime[6..8])));
 > }
 > }
 >
 > If I write to the sctruct and then print it I'm able to see the
 > SysTime variable with a value.
 > writeln(preEv) //previousEvents("140212", "05:13:26", "9 140212
 > 05:13:26 d", "2012-Feb-14 05:13:26")
 >
 > but if trying to get the value from the SysTime variable I get a
 > Segmentation fault.

Probably because esystime member is no initialized.

 > Trying to read any other variable inside this
 > struct will not be a problem.
 >
 > writeln (preEv.esystime.day) // will compile but segfaults
 >
 > On DMD32 D Compiler v2.058
 >
 > Any correct way to do this?
 >
 > Thank you.

Ali



More information about the Digitalmars-d-learn mailing list