Hi, I came across this here in utils.c which is part of top: /* * How do we know that 16 will suffice? * Because the biggest number that we will * ever convert will be 2^32-1, which is 10 * digits. */ char *itoa(val) register int val; int can be 64 bits on a amd64 machine. Why is the author of this code so sure that we will never cross the 32 bit boundary? Erich
On Sun, 1 Feb 2015 17:51:59 +0800 Erich Dollansky <erichsfreebsdlist at alogt.com> wrote:> Hi, > > I came across this here in utils.c which is part of top: > > > /* > * How do we know that 16 will suffice? > * Because the biggest number that we > will > * ever convert will be 2^32-1, which > is 10 > * digits. > */ > > char *itoa(val) > > register int val; > > int can be 64 bits on a amd64 machine. Why is the author of this code > so sure that we will never cross the 32 bit boundary? > > ErichI thought an 'int' was a 32bit number on amd64 arch. #include <stdio.h> #include <stdlib.h> int main (void) { printf ("%zd\n", sizeof (int)); exit (0); } Paul. -- Paul Koch | Founder, CEO AKIPS Network Monitor http://www.akips.com
Erich Dollansky wrote this message on Sun, Feb 01, 2015 at 17:51 +0800:> int can be 64 bits on a amd64 machine. Why is the author of this code > so sure that we will never cross the 32 bit boundary?Per others, int is currently 32bits on all platforms we support... I guess adding: CTASSERT(sizeof(int) <= 4); would help fix your concern? at least now the expectation is codified and if it breaks, the build will break.. -- John-Mark Gurney Voice: +1 415 225 5579 "All that I will do, has been done, All that I have, has not."