gpsd-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gpsd-dev] TIMEDIFF()


From: Gary E. Miller
Subject: [gpsd-dev] TIMEDIFF()
Date: Mon, 4 Nov 2013 19:30:46 -0800

Yo Eric!

For some reason my git pull was not getting timedrift_t earlier.  I
see where you are going with it and it sort of makes sense.  It does
need some comments.

The macro is prolly a no-go:

#define TIMEDIFF(drift) ((((drift)->real.tv_sec - (drift)->clock.tv_sec)*1e9)\
                         + ((drift)->real.tv_nsec - (drift)->clock.tv_nsec))

You'll notice that this does not fit in a long:

(drift)->clock.tv_sec)*1e9 + (drift)->clock.tv_nsec)

So if the compiler reorders from right to left the value will overflow.  That
is why statements were not previously combined.  Doing it on two lines
is no guarantee that the compiler will not reorder but has worked so far.

Combining it as you have done is much more dangerous and to be safe needs
some compiler hints.

RGDS
GARY
---------------------------------------------------------------------------
Gary E. Miller Rellim 109 NW Wilmington Ave., Suite E, Bend, OR 97701
        address@hidden  Tel:+1(541)382-8588

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]