473,804 Members | 2,249 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Time typedef structure

I was hoping some of you might be able to help me understand the
following code defining a typedef for a time query to the WINAPI. I
understand the basics of what's going on, I just don't understand the
format of the output it should provide. Here is the code below are some
more comments:

typedef struct tagGTime32
{
union
{
struct
{
unsigned char chSec100;
unsigned char chSec;
unsigned char chMin;
unsigned char chHour;
};

unsigned long dwTime;
};
}GTime32;
#pragma pack()

#define MAKEWTIME(h, m, s) ((unsigned long)(\
((unsigned char)(0)) << 0 |\
((unsigned char)(s)) << 8 |\
((unsigned char)(m)) << 16 |\
((unsigned char)(h)) << 24))
#ifdef __cplusplus
extern "C"
{
#endif//__cplusplus
int WINAPI GetGTime32Secon ds(const GTime32 *gt);
int WINAPI DiffGTime32Seco nds(const GTime32 *gt1, const GTime32 *gt2);
int WINAPI GetGTime32Minut es(const GTime32 *gt);
int WINAPI DiffGTime32Minu tes(const GTime32 *gt1, const GTime32 *gt2);
#ifdef __cplusplus
}
> end code


When I make a call to a class which uses this def to store the time of
a particular event under a record (*pRcd), I get a value returned that
I'm confused about. I'm defining the trace output as an integer ("%d",
pRcd->gtime) and am returned a 9 digit number. However, if it were time
measured in miliseconds, it should be a max of 8... which leads me to
believe I don't really understand what's going on. If anyone could help
explain what I'm missing, I would be very grateful.

Regards,
Lorn

Jul 23 '05 #1
6 1824
Lorn wrote:
I was hoping some of you might be able to help me understand the
following code defining a typedef for a time query to the WINAPI. I
understand the basics of what's going on, I just don't understand the
format of the output it should provide. Here is the code below are some
more comments:

typedef struct tagGTime32
{
union
{
struct
{
unsigned char chSec100;
unsigned char chSec;
unsigned char chMin;
unsigned char chHour;
};

unsigned long dwTime;
};
}GTime32;
#pragma pack()

#define MAKEWTIME(h, m, s) ((unsigned long)(\
((unsigned char)(0)) << 0 |\
((unsigned char)(s)) << 8 |\
((unsigned char)(m)) << 16 |\
((unsigned char)(h)) << 24))
#ifdef __cplusplus
extern "C"
{
#endif//__cplusplus
int WINAPI GetGTime32Secon ds(const GTime32 *gt);
int WINAPI DiffGTime32Seco nds(const GTime32 *gt1, const GTime32 *gt2);
int WINAPI GetGTime32Minut es(const GTime32 *gt);
int WINAPI DiffGTime32Minu tes(const GTime32 *gt1, const GTime32 *gt2);
#ifdef __cplusplus
}

>>end code


When I make a call to a class


"make a call to a class"? Is your class a functor?
which uses this def to store the time of
a particular event under a record (*pRcd), I get a value returned that
I'm confused about. I'm defining the trace output as an integer ("%d",
pRcd->gtime) and am returned a 9 digit number.
A number? From a struct? I don't see any conversion from GTime32 to
an int...
However, if it were time
measured in miliseconds, it should be a max of 8...
Why 8? What's the limit on 'chHour' member in the time value? If it's
255, then (255*3600*1000 - 1) is the number of milliseconds the struct
can represent, no? But it doesn't represent it in milliseconds. It has
some funky format with _centiseconds_ as the smallest subdivision. So,
what number are you getting and why? To know that we need to see _your_
code as well.
which leads me to
believe I don't really understand what's going on. If anyone could help
explain what I'm missing, I would be very grateful.


Please post the code that uses that struct and shows how you print that
value (and which value).

V
Jul 23 '05 #2
Lorn wrote:
I was hoping some of you might be able to help me understand the
following code defining a typedef for a time query to the WINAPI. I
understand the basics of what's going on, I just don't understand the
format of the output it should provide. Here is the code below are some
more comments:

typedef struct tagGTime32
{
union
{
struct
{
unsigned char chSec100;
unsigned char chSec;
unsigned char chMin;
unsigned char chHour;
};

unsigned long dwTime;
};
}GTime32;
#pragma pack()

#define MAKEWTIME(h, m, s) ((unsigned long)(\
((unsigned char)(0)) << 0 |\
((unsigned char)(s)) << 8 |\
((unsigned char)(m)) << 16 |\
((unsigned char)(h)) << 24))
#ifdef __cplusplus
extern "C"
{
#endif//__cplusplus
int WINAPI GetGTime32Secon ds(const GTime32 *gt);
int WINAPI DiffGTime32Seco nds(const GTime32 *gt1, const GTime32 *gt2);
int WINAPI GetGTime32Minut es(const GTime32 *gt);
int WINAPI DiffGTime32Minu tes(const GTime32 *gt1, const GTime32 *gt2);
#ifdef __cplusplus
}
>>end code


When I make a call to a class which uses this def to store the time of
a particular event under a record (*pRcd), I get a value returned that
I'm confused about. I'm defining the trace output as an integer ("%d",
pRcd->gtime) and am returned a 9 digit number. However, if it were time
measured in miliseconds, it should be a max of 8... which leads me to
believe I don't really understand what's going on. If anyone could help
explain what I'm missing, I would be very grateful.

Regards,
Lorn


GTime32 is a union which overlays 4 distinct time fields onto
an unsigned long. It's data can be accessed as a single
unsigned long (dwTime) or via the individual time fields
(chHour, chMin, chSec, chSec100).

Compile and run this sample C program may shed some light on it
for you:

#include <stdio.h>

/* would normally include the header file defining
* GTime32 here, but this is a cut-and-paste of the
* relevant code.
*/
typedef struct tagGTime32
{
union
{
struct
{
unsigned char chSec100;
unsigned char chSec;
unsigned char chMin;
unsigned char chHour;
};

unsigned long dwTime;
};
}GTime32;
#define MAKEWTIME(h, m, s) ((unsigned long)(\
((unsigned char)(0)) << 0 |\
((unsigned char)(s)) << 8 |\
((unsigned char)(m)) << 16 |\
((unsigned char)(h)) << 24))

/* end of the GTime32 cut-and-paste */

int main()
{
GTime32 gtime;

/* create a time of 24:45:30.00 in gtime */
gtime.dwTime = MAKEWTIME(24, 45, 30);

printf("setting gtime.dwTime = MAKEWTIME(24, 45, 30)\n");

printf("gtime.d wTime (time as a long) = %ld (0x%lx)\n",
gtime.dwTime, gtime.dwTime);

printf("gtime.c hHour = %02d (0x%02x)\n",
gtime.chHour, gtime.chHour);

printf("gtime.c hMin = %02d (0x%02x)\n",
gtime.chMin, gtime.chMin);

printf("gtime.c hSec = %02d (0x%02x)\n",
gtime.chSec, gtime.chSec);

printf("gtime.c hSec100 = %02d (0x%02x)\n",
gtime.chSec100, gtime.chSec100) ;

printf("gtime as a time = %02d:%02d:%02d. %02d\n",
gtime.chHour, gtime.chMin, gtime.chSec, gtime.chSec100) ;

return 0;
}

Regards,
Larry
Jul 23 '05 #3
Larry I Smith wrote:
Lorn wrote:
I was hoping some of you might be able to help me understand the
following code defining a typedef for a time query to the WINAPI. I
understand the basics of what's going on, I just don't understand the
format of the output it should provide. Here is the code below are some
more comments:

typedef struct tagGTime32
{
union
{
struct
{
unsigned char chSec100;
unsigned char chSec;
unsigned char chMin;
unsigned char chHour;
};

unsigned long dwTime;
};
}GTime32;
#pragma pack()

#define MAKEWTIME(h, m, s) ((unsigned long)(\
((unsigned char)(0)) << 0 |\
((unsigned char)(s)) << 8 |\
((unsigned char)(m)) << 16 |\
((unsigned char)(h)) << 24))
#ifdef __cplusplus
extern "C"
{
#endif//__cplusplus
int WINAPI GetGTime32Secon ds(const GTime32 *gt);
int WINAPI DiffGTime32Seco nds(const GTime32 *gt1, const GTime32 *gt2);
int WINAPI GetGTime32Minut es(const GTime32 *gt);
int WINAPI DiffGTime32Minu tes(const GTime32 *gt1, const GTime32 *gt2);
#ifdef __cplusplus
}
>>>end codeWhen I make a call to a class which uses this def to store the time of
a particular event under a record (*pRcd), I get a value returned that
I'm confused about. I'm defining the trace output as an integer ("%d",
pRcd->gtime) and am returned a 9 digit number. However, if it were time
measured in miliseconds, it should be a max of 8... which leads me to
believe I don't really understand what's going on. If anyone could help
explain what I'm missing, I would be very grateful.

Regards,
Lorn


GTime32 is a union which overlays 4 distinct time fields onto
an unsigned long. It's data can be accessed as a single
unsigned long (dwTime) or via the individual time fields
(chHour, chMin, chSec, chSec100).

Compile and run this sample C program may shed some light on it
for you:

#include <stdio.h>

/* would normally include the header file defining
* GTime32 here, but this is a cut-and-paste of the
* relevant code.
*/
typedef struct tagGTime32
{
union
{
struct
{
unsigned char chSec100;
unsigned char chSec;
unsigned char chMin;
unsigned char chHour;
};

unsigned long dwTime;
};
}GTime32;
#define MAKEWTIME(h, m, s) ((unsigned long)(\
((unsigned char)(0)) << 0 |\
((unsigned char)(s)) << 8 |\
((unsigned char)(m)) << 16 |\
((unsigned char)(h)) << 24))

/* end of the GTime32 cut-and-paste */

int main()
{
GTime32 gtime;

/* create a time of 24:45:30.00 in gtime */
gtime.dwTime = MAKEWTIME(24, 45, 30);

printf("setting gtime.dwTime = MAKEWTIME(24, 45, 30)\n");

printf("gtime.d wTime (time as a long) = %ld (0x%lx)\n",
gtime.dwTime, gtime.dwTime);

printf("gtime.c hHour = %02d (0x%02x)\n",
gtime.chHour, gtime.chHour);

printf("gtime.c hMin = %02d (0x%02x)\n",
gtime.chMin, gtime.chMin);

printf("gtime.c hSec = %02d (0x%02x)\n",
gtime.chSec, gtime.chSec);

printf("gtime.c hSec100 = %02d (0x%02x)\n",
gtime.chSec100, gtime.chSec100) ;


Oops, the format string in the following printf() is incorrect.
The ending ".%02d\n" should be ".%2d\n" or even just ".%d\n".
The way I had it originally will cause 2.3 seconds to be
displayed as "02.03" instead of "02.3".

printf("gtime as a time = %02d:%02d:%02d. %02d\n",
gtime.chHour, gtime.chMin, gtime.chSec, gtime.chSec100) ;

return 0;
}

Regards,
Larry


Of course, you can also set the 4 time fields directly:

gtime.chHour = 10;
gtime.chMin = 15;
etc.

If you will be setting all of the individual fields
directly for an new uninitialized gtime, then you should
do 'gtime.dwTime = 0' first to ensure that any bits in the
unsigned long that are NOT used by the 4 time fields are
set to zero.

Regards,
Larry
Jul 23 '05 #4
Larry I Smith wrote:
Larry I Smith wrote:
[snip]

Oops, the format string in the following printf() is incorrect.
The ending ".%02d\n" should be ".%2d\n" or even just ".%d\n".
The way I had it originally will cause 2.3 seconds to be
displayed as "02.03" instead of "02.3".

printf("gtime as a time = %02d:%02d:%02d. %02d\n",
gtime.chHour, gtime.chMin, gtime.chSec, gtime.chSec100) ;

return 0;
}

[snip]

Grrr, I shouldn't be allowed to code before I get my
first cup of coffee...

To correct my above correction:

The ending ".%02d\n" should be ".%-2d\n" or even just ".%d\n".
Depending on whether or not you desire a constant fixed length
output from printf/sprintf for any random time value.

Larry
Jul 23 '05 #5
Wow, thank you very much Victor and Larry. Victor for getting me to go
back to the code (this wasn't my code by the way, someone else's I was
trying to figure out) and study it harder so I could give a proper
reply. Larry for showing the exact example of what I needed. I now have
it printing the correct time. Woohoo, it was a long time coming.

Thanks again, this is such a great group.

Lorn

Jul 23 '05 #6
Lorn wrote:
Wow, thank you very much Victor and Larry. Victor for getting me to go
back to the code (this wasn't my code by the way, someone else's I was
trying to figure out) and study it harder so I could give a proper
reply. Larry for showing the exact example of what I needed. I now have
it printing the correct time. Woohoo, it was a long time coming.

Thanks again, this is such a great group.

Lorn


Be sure to read my last (3rd) post that includes the correction
to my first correction...

Larry
Jul 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
425
by: Vu Pham | last post by:
I think this problem relates to either c or c++ ( but I am not sure which one ) so I post to both of these news group. I am sorry if I did something wrong here. Is there any difference between these two declarations : 1. void * functionA( char * p, int s, int * e ); and
8
2384
by: J Krugman | last post by:
My compiler complains if I do something like this typedef struct { node *next; } node; but it's OK with typedef struct superfluous_identifier { superfluous_identifier *next;
10
4792
by: Bart Goeman | last post by:
Hi, I have a question about how to put redundant information in data structures, initialized at compile time. This is often necessary for performance reasons and can't be done at run time (data structures are read only) Ideally one should be able to put the redundant information there automatically so no mistakes are possible, but in a lot of case I see no way how to do it.
3
1592
by: Diego Acevedo | last post by:
How do I assess members of a typedef struct? Example: typedef struct { Int16 data1; Int32 data2; Char stringData; } MyRecordType;
8
2363
by: Ronny Mandal | last post by:
Consider these two: Typedef struct { int foo, bar } FooBar; struct FooBar { int foo, bar }; What woul be the only difference here; just that I can create new instances by 'Foobar fb, *pfb', and the second demands that I prefix with struct? struct FooBar fb, *pfb?
15
2576
by: Ian Bush | last post by:
Hi All, I'm a bit confused by the following which is causing one of our user's codes fail in compilation: typedef struct SctpDest_S; 1) Is this standard ? 2) If so ( or even if not so ! ) what is it supposed to do ?
8
8111
by: Guillaume Dargaud | last post by:
I just saw the following two lines in /usr/include/usb.h and my head is spinning: struct usb_dev_handle; typedef struct usb_dev_handle usb_dev_handle; What is that supposed to mean ? I assume the first line is a forward declaration. I can't find a definition for it, so does that mean it's like a void ? Apparently gdb is confused as well as I can't seem to display anything based
2
2517
by: copx | last post by:
What is wrong with the following code? My compiler (GCC) produces a warning which states that the initialisation values of a local struct are "not computable at load time". A warning is not equal to an error, but it usually suggests that the code is at least questionable. I do not see anything questionable... This program demonstrates the issue. I get the warning whenever I pass a pointer to a structure and use the fields of that...
4
1842
by: cpptutor2000 | last post by:
Could someone please help me? I have the following C struct. typedef struct _FIREWALL_RULE_INFO { ULONG Precedence; BOOL bEnabled; BOOL bLoggingEnabled; BOOL bAllowFragments; BOOL bAllowInbound; /* only used if 'SohoFirewallModel' is enabled */
0
9714
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10599
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10346
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10347
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10090
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9173
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6863
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4308
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3832
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.