2010-06-16 19:07:48

by Vladislav Bolkhovitin

[permalink] [raw]
Subject: How to printk/sprintf uint64_t on Sparc without format and argument types mismatch

Hello,

We in SCST project need to printk/sprintf variables of type uint64_t.
Size of those variables is required to be 64-bit integer. On x86 we
printk/sprintf them as %lld, but on Sparc we have a compiler warnings like:

scst/src/scst_targ.c:2136: warning: format ?%llx? expects type ?long
long unsigned int?, but argument 4 has type ?uint64_t?.

It is because on Sparc uint64_t defined as unsigned long, but on x86 -
as unsigned long long.

Sure, we can cast all the cases to unsigned long long, but we wonder,
maybe there is a more elegant way to do that without the warning? For
instance, like %z for size_t or PRId64 in the user space.

Thanks,
Vlad


2010-06-16 19:29:37

by Kyle McMartin

[permalink] [raw]
Subject: Re: How to printk/sprintf uint64_t on Sparc without format and argument types mismatch

On Wed, Jun 16, 2010 at 11:08:03PM +0400, Vladislav Bolkhovitin wrote:
> scst/src/scst_targ.c:2136: warning: format ?%llx? expects type ?long
> long unsigned int?, but argument 4 has type ?uint64_t?.
>
> It is because on Sparc uint64_t defined as unsigned long, but on x86 -
> as unsigned long long.
>

>From your other mail, it looks like you're using 2.6.26... this is
ancient! Sparc has since been fixed to use unsigned long long for u64.

commit 9018113649348c689da107166c05d436cd52e7bf
Author: Sam Ravnborg <[email protected]>
Date: Tue Jan 6 13:19:28 2009 -0800

sparc64: Use unsigned long long for u64.

regards, Kyle

2010-06-16 20:36:32

by David Miller

[permalink] [raw]
Subject: Re: How to printk/sprintf uint64_t on Sparc without format and argument types mismatch

From: Vladislav Bolkhovitin <[email protected]>
Date: Wed, 16 Jun 2010 23:08:03 +0400

> We in SCST project need to printk/sprintf variables of type
> uint64_t. Size of those variables is required to be 64-bit integer. On
> x86 we printk/sprintf them as %lld, but on Sparc we have a compiler
> warnings like:
>
> scst/src/scst_targ.c:2136: warning: format ?%llx? expects type ?long
> long unsigned int?, but argument 4 has type ?uint64_t?.
>
> It is because on Sparc uint64_t defined as unsigned long, but on x86 -
> as unsigned long long.

You must use %ll and explicitly cast the argument to "long long".
????{.n?+???????+%?????ݶ??w??{.n?+????{??G?????{ay?ʇڙ?,j??f???h?????????z_??(?階?ݢj"???m??????G????????????&???~???iO???z??v?^?m???? ????????I?