Board index » cppbuilder » Comparing two dates

Comparing two dates


2006-05-27 03:40:21 AM
cppbuilder6
We know this structure, which is in io.h:
struct ftime {
unsigned ft_tsec : 5; /* Two second interval */
unsigned ft_min : 6; /* Minutes */
unsigned ft_hour : 5; /* Hours */
unsigned ft_day : 5; /* Days */
unsigned ft_month : 4; /* Months */
unsigned ft_year : 7; /* Year */
};
It contains exactly 32 bits and obviously it is stored as an integer.
But I cannot compare then.
a<b fails and so does (unsigned int)a < (unsigned int)b)
Is there a simple way to do it?
--
Jos?
 
 

Re:Comparing two dates

I don't know how you are trying to do it but here are two functions, each of
which does the compare and each of which compiled without complaint:
-----------------------------------------
struct ftime {
unsigned ft_tsec : 5; /* Two second interval */
unsigned ft_min : 6; /* Minutes */
unsigned ft_hour : 5; /* Hours */
unsigned ft_day : 5; /* Days */
unsigned ft_month : 4; /* Months */
unsigned ft_year : 7; /* Year */
};
bool ASmallerThanB(ftime &a, ftime &b)
{
return (*reinterpret_cast<unsigned int *>(&a)) <
(*reinterpret_cast<unsigned int *>(&b));
}
bool ASmallerThanB2(ftime &a, ftime &b)
{
__asm {
mov eax,[a]
mov ebx,[b]
}
return _EAX < _EBX;
}
-----------------------------------------
. Ed
Quote
Jos?wrote in message
news: XXXX@XXXXX.COM ...

We know this structure, which is in io.h:

struct ftime {
unsigned ft_tsec : 5; /* Two second interval */
unsigned ft_min : 6; /* Minutes */
unsigned ft_hour : 5; /* Hours */
unsigned ft_day : 5; /* Days */
unsigned ft_month : 4; /* Months */
unsigned ft_year : 7; /* Year */
};

It contains exactly 32 bits and obviously it is stored as an integer.
But I cannot compare then.
a<b fails and so does (unsigned int)a < (unsigned int)b)

Is there a simple way to do it?
 

Re:Comparing two dates

Ed Mulroy wrote:
Quote
bool ASmallerThanB2(ftime &a, ftime &b)
{
__asm {
mov eax,[a]
mov ebx,[b]
Using ebx could be a problem (reserved for compiler use).
edx would be a better choice.
Quote
}

return _EAX < _EBX;
}
 

{smallsort}

Re:Comparing two dates

On Fri, 26 May 2006 16:04:36 -0400, "Ed Mulroy"
< XXXX@XXXXX.COM >wrote in
borland.public.cppbuilder.language.cpp:
Quote
bool ASmallerThanB(ftime &a, ftime &b)
{
return (*reinterpret_cast<unsigned int *>(&a)) <
(*reinterpret_cast<unsigned int *>(&b));
}

bool ASmallerThanB2(ftime &a, ftime &b)
{
__asm {
mov eax,[a]
mov ebx,[b]
}

return _EAX < _EBX;
}
-----------------------------------------
I would never have thought of these myself. Thanks to you I can now
make my own version, which is:
bool ASmallerThanB(ftime a, ftime b)
{ return ( (*(unsigned int*)&a) < (*(unsigned int*)&b)); }
--
Jos?
 

Re:Comparing two dates

At 19:15:17, 27.05.2006, Jos?wrote:
Quote
I would never have thought of these myself. Thanks to you I can now
make my own version, which is:

bool ASmallerThanB(ftime a, ftime b)
{ return ( (*(unsigned int*)&a) < (*(unsigned int*)&b)); }
Be careful! This does not give the correct result in cases of overflow.
--
Rudy Velthuis [TeamB] rvelthuis.de/
"If thereís one thing I know itís God does love a good joke."
-- Hugh Elliott, Standing Room Only weblog, 05-01-04
 

Re:Comparing two dates

Jos?< XXXX@XXXXX.COM >wrote:
Quote
On Fri, 26 May 2006 16:04:36 -0400, "Ed Mulroy"
< XXXX@XXXXX.COM >wrote in
borland.public.cppbuilder.language.cpp:

>bool ASmallerThanB(ftime &a, ftime &b)
>{
>return (*reinterpret_cast<unsigned int *>(&a)) <
>(*reinterpret_cast<unsigned int *>(&b));
>}
>
[asm example snipped]

I would never have thought of these myself. Thanks to you I can now
make my own version, which is:

bool ASmallerThanB(ftime a, ftime b)
{ return ( (*(unsigned int*)&a) < (*(unsigned int*)&b)); }
What's wrong with Ed's version? (<ahem>Apart from it
not being usable for 'const ftime' objects, that is.)
I think 'reinterpret_cast<>()' is a lot clearer in
showing what you're actually doing than the C-style
cast you used. (And it won't accidently cast away
'const' either, in cases where this might matter.)
Schobi
--
XXXX@XXXXX.COM is never read
I'm Schobi at suespammers dot org
"The sarcasm is mightier than the sword."
Eric Jarvis