By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,562 Members | 1,244 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,562 IT Pros & Developers. It's quick & easy.

weird time_t problem!

P: n/a
having a really weird little bug w/ time_t...check it out:

I have the following code (simplified here):

#include <time.h>
class A
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
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
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
- 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
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.