LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How do you initialize a struct tm type in CVI ?

Hi

I use WIN2K, CVI 6.0 FULL,

I always get a message
Warning: Local 'TimeValue' has not been fully initialized.

TimeValue is declared as:
struct tm TimeValue;

But how do you initialize a structure ?, I just want to clear that message.

Thank you,
0 Kudos
Message 1 of 4
(6,254 Views)
Initializing a struct is similar to initializing a class. Usually you use pointers, i.e. struct tm *pTimeValue in which case you would need to malloc the space for the pointer, then init each of the member variables. Either way, the struct tm is defined in time.h and has the following member variables:

int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;

So you want to init each of these before they are used, i.e. TimeValue.tm_sec = 0, or pTimeValue->tm_sec = 0, if you're using a pointer.
Message 2 of 4
(6,254 Views)
I find it quicker and safer to initialise the whole memory at one go using memset, e.g.

memset(&tm, 0, sizeof(tm));
0 Kudos
Message 3 of 4
(6,254 Views)
Aarrgh! I can't seem to edit my post. I should have coded:

memset(pTimeValue, 0, sizeof(tm));

Perhaps the moderator can amend my earlier comment and delete this one.
0 Kudos
Message 4 of 4
(6,254 Views)