473,404 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

time_t oddity?

I have the following code (simplified here):

#include <time.h>
class A
{
public:
char *aString;
int aNum;
time_t aTime;
}

I have a function in another class that takes an initialized A object.

#include <time.h>
void doSomething(A *aObj)
{
time_t valueOfATime = aObj->aTime;
int valueOfANum = aObj->aNum;
// other stuff
}

--------------------------------------------------------------------------------
The problem is that the valueOfATime DOES NOT equal the aObj->aTime.
It gets messed up. Debugging the program, I see the following values during
the doSomething function:
aObj->aTime = 0x000000004149f4fc << CORRECT
and
valueOfATime = 0x4149f4fccdcdcdcd << WRONG

valueOfATime != aTime even though it was just set to = aTime!

Now, the weird part:
I can fix the problem by moving the aTime time_t variable to a different
position within the A class. As long as it is *not the last variable in the
class definition*, the doSomething function works fine. For example, the
following class def works:

class A
{
public:
char *aString;
time_t aTime; << switched positions w/ aNum
int aNum;
}

After the switch I can still read the value of int aNum without a hitch in
the doSomething function. Is there some reason that time_t cannot be the
last variable in the class? I feel like I must be doing something else
wrong...but I've tried a bunch of different things and placing time_t at the
end of the class seems to be the only thing that makes a difference.

two other notes:
- sizeof(time_t) returns 8, although in the debugger the values are int64.
Could that have something to do with it not being good at the end of the
class?
- The doSomething function is within a .lib that is compiled into a .dll.
Class A is also within the .lib, but the class's header file (where the
time_t switch of position can make a difference) is exposed to the .dll and
included in the .dll compilation since the .dll code needs the the class A
defination so it can use it.

I could understand if my second note was making a difference...but I am
fairly sure I'm linking in the same <time.h>...

Please help out! thanks!

- Zack
Nov 17 '05 #1
0 1248

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

Similar topics

1
by: Anand CS | last post by:
Hi All I have question regarding time data structures... I have 64 bit unsigned microsecond resolution (unsigned __int64 for windows/and unsigned long long for others) variable. It stores the...
4
by: Dave Sinkula | last post by:
I have been told conflicting advice. Please offer comments regarding the following. ===== I visited Ben Pfaff's "When are casts appropriate?" page....
6
by: j0mbolar | last post by:
i've read recently that time_t doesn't have to be in second resolution but if it isn't, then what resolution could it be in? microseconds, milliseconds, are all valid? also, does anyone know...
8
by: Ian Pilcher | last post by:
When adding two values of type time_t, how can I check for overflow? Maybe I'm just brain-cramped today, but I can't figure out how to do it. Thanks! --...
0
by: Zwyatt | last post by:
having a really weird little bug w/ time_t...check it out: I have the following code (simplified here): #include <time.h> class A { public: char *aString; int aNum;
8
by: Henrik Goldman | last post by:
I have strings like "2006-03-26 21.51" which I would like to convert into time_t. I know that the string is in localtime. So far I've written the following code: time_t...
45
by: loudking | last post by:
Hello, all I don't quite understand what does ((time_t)-1) mean when I execute "man 2 time" RETURN VALUE On success, the value of time in seconds since the Epoch is retu rned. On error,...
7
by: Nick Keighley | last post by:
Hi, this is probably quite easy... How do I convert a UTC string into a time_t? eg. "2007-12-18 13:37:26" - a time_t. Now FAQ 13.3 says use mktime() to convert a struct tm into a time_t...
8
by: Abubakar | last post by:
Hi, Lets say I have three integers (date, month, and year) as part of a struct lets say like struct mydate{ int day, month, year}; I want to add x number of days to this date. And it should be a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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...
0
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,...

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.