Re: printk and long long

From: H. Peter Anvin
Date: Wed Feb 11 2004 - 18:55:53 EST


Followup to: <yw1xn07pw6sy.fsf@xxxxxx>
By author: mru@xxxxxx (=?iso-8859-1?q?M=E5ns_Rullg=E5rd?=)
In newsgroup: linux.dev.kernel
>
> Andreas Schwab <schwab@xxxxxxx> writes:
>
> > mru@xxxxxx (Måns Rullgård) writes:
> >
> >> What is the proper way to deal with printing an int64_t when int64_t
> >> can be either long or long long depending on machine?
> >
> > PRId64 from <inttypes.h> (replace d with the desired format character).
> > This is for user space, not sure whether that is acceptable for kernel
> > code (<intttypes.h> is not one of the required headers for freestanding
> > implementations).
>
> That should work for userspace. What standard specifies those?
> What about kernel sources?
>

C99 defines those.

Another (frequently easier) way is to cast to (intmax_t) and use the %j size modifier:

printf("foo = %jd\n", (intmax_t)foo);

-hpa
--
PGP public key available - finger hpa@xxxxxxxxx
Key fingerprint: 2047/2A960705 BA 03 D3 2C 14 A8 A8 BD 1E DF FE 69 EE 35 BD 74
"The earth is but one country, and mankind its citizens." -- Bahá'u'lláh
Just Say No to Morden * The Shadows were defeated -- Babylon 5 is renewed!!
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/