Am I missing something simple here?

Eric S. Raymond esr at thyrsus.com
Tue Jan 3 23:39:11 UTC 2017


The l_fp datatype is used to represent timestamps with fractional seconds.
Here's how it's now declared and accessed:

/*
 *    0			  1		      2			  3
 *    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
 *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 *   |			       Integral Part			     |
 *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 *   |			       Fractional Part			     |
 *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 *
 */
typedef struct {
	union {
		uint32_t Xl_ui;		/* unsigned integral part */
		int32_t Xl_i;		/* signed integral part */
	} Ul_i;
	uint32_t	l_uf;
} l_fp;

#define lfpfrac(n)		((n).l_uf)
#define setlfpfrac(n, v)	(n).l_uf = (v)
#define lfpsint(n)		(n).Ul_i.Xl_i
#define setlfpsint(n, v)	(n).Ul_i.Xl_i = (v)
#define bumplfpsint(n, i)	(n).Ul_i.Xl_i += (i)
#define lfpuint(n)		(n).Ul_i.Xl_ui
#define setlfpuint(n, v)	(n).Ul_i.Xl_ui = (v)
#define bumplfpuint(n, i)	(n).Ul_i.Xl_ui += (i)

It should be possible to typedef l_fp as a uint64_t and rewrite the
macros to access the upper and lower halfwords.  This would be
desirable, as much code would be simplified if we could use
scalar comparison operators on these timestamps.

I've done the hard part - there are no direct accesses to l_fp
members anywhere outside these macros, and there is a unit test for
them in teststs/libntp/lfpfunc.c.  

But for some reason I can't seem to get the easy part - replacing te
macros - right.  Anybody else want to take a swingth at this?
-- 
		<a href="http://www.catb.org/~esr/">Eric S. Raymond</a>

All governments are more or less combinations against the
people. . .and as rulers have no more virtue than the ruled. . .
the power of government can only be kept within its constituted
bounds by the display of a power equal to itself, the collected
sentiment of the people.
	-- Benjamin Franklin Bache, in a Phildelphia Aurora editorial 1794


More information about the devel mailing list