[Nagios-devel] warning: left shift count >= width of type (i386)

Ricardo Jose Maraschini ricardo.maraschini at opservices.com.br
Mon Sep 3 17:35:16 UTC 2012

OK, I'm not pretty sure about following, but here we go.
I tried to compile current nagios on a i386 arch and received the
following warning:

squeue.c:34:  warning: left shift count >= width of type

If i'm right, long is four bytes long on i386 arch, and as tv_sec is 
a long(accordingly to gettimeofday(2)) the result of line 34 on squeue.c
is unpredictable.

Am I right or I'm missing something?

Compiling on a sparc64 and in a x86_64 environment i haven't received
the same warning. On these architectures, sizeof(long) shows me 8 bytes.

What are the performance implications of my patch below?


--- lib/squeue.c	(revision 2138)
+++ lib/squeue.c	(working copy)
@@ -31,7 +31,12 @@
 static pqueue_pri_t evt_compute_pri(struct timeval *tv)
-	return (tv->tv_sec << 32) | tv->tv_usec;
+	pqueue_pri_t pri = 0;
+	pri = pri | tv->tv_sec;
+	pri = (pri << 32) | tv->tv_usec;
+	return pri;
 static int sq_cmp_pri(pqueue_pri_t next, pqueue_pri_t cur)

More information about the Nagios-devel mailing list