The format strings for printf(3C), sprintf(3C), scanf(3C),
and sscanf(3C) might need
to be changed for long
or pointer arguments. For pointer arguments, the
conversion operation given in the format string should be %p to
work in both the 32-bit and 64-bit environments. For example,
char *buf; struct dev_info *devi; ... (void) sprintf(buf, "di%x", (void *)devi);
produces the warning:
warning: function argument (number) type inconsistent with format sprintf (arg 3) void *: (format) int
Use the following code to produce clean results:
char *buf; struct dev_info *devi; ... (void) sprintf(buf, "di%p", (void *)devi);
Also check to be sure that the storage pointed to by buf
is large
enough to contain 16 digits. For long
arguments, the long
size
specification, l, should be prepended to the conversion operation
character in the format string. For example,
size_t nbytes; ulong_t align, addr, raddr, alloc; printf("kalloca:%d%%%d from heap got %x.%x returns %x\n", nbytes, align, (int)raddr, (int)(raddr + alloc), (int)addr);
produces the warnings:
warning: cast of 64-bit integer to 32-bit integer warning: cast of 64-bit integer to 32-bit integer warning: cast of 64-bit integer to 32-bit integer
The following code will produce clean results:
size_t nbytes; ulong_t align, addr, raddr, alloc; printf("kalloca:%lu%%%lu from heap got %lx.%lx returns %lx\n", nbytes, align, raddr, raddr + alloc, addr);