468,765 Members | 1,710 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,765 developers. It's quick & easy.

time_t oddity?

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
0 1078

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Anand CS | last post: by
4 posts views Thread by Dave Sinkula | last post: by
6 posts views Thread by j0mbolar | last post: by
8 posts views Thread by Ian Pilcher | last post: by
reply views Thread by Zwyatt | last post: by
8 posts views Thread by Henrik Goldman | last post: by
45 posts views Thread by loudking | last post: by
7 posts views Thread by Nick Keighley | last post: by
8 posts views Thread by Abubakar | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.