From: "Richard B. Johnson" <root@chaos.analogic.com>
To: wdebruij@dds.nl
Cc: sting sting <zstingx@hotmail.com>, linux-kernel@vger.kernel.org
Subject: Re: printk and long long
Date: Wed, 11 Feb 2004 10:23:38 -0500 (EST) [thread overview]
Message-ID: <Pine.LNX.4.53.0402111021160.18798@chaos> (raw)
In-Reply-To: <1076506513.402a2f9120fb8@webmail.dds.nl>
On Wed, 11 Feb 2004 wdebruij@dds.nl wrote:
> how about simply using a shift to output two regular longs, i.e.
>
> printk("%ld%ld",loff_t >> (sizeof(long) * 8), loff_t << sizeof(long) * 8 >>
> sizeof(long) * 8);
>
> perhaps you could even place this ghastly code in a macro if you have to access
> it often (so that you don't have to look at it :)?
>
> I know it's not pretty, but at least the %ld is considered standard printf
> functionality. I don't think %lld (even if it is implemented in some printf
> derivates) can be considered portable.
>
> Willem
> Citeren sting sting <zstingx@hotmail.com>:
>
> > Hello,
> > I am trying to perfrom printk with a variable of type long long.
> > (loff_t is that type and it is long long , as can be seen in
> > posix+types.h).
> > what is the format string for such a type ?
> > I had tried %lld" but it gace wrpng results.
> > regards,
> > sting
This is probably portable. I could do it much simpler in
assembly but it wouldn't be portable.
Printing both unsigned long long and signed long long.
#include <stdio.h>
unsigned long long tester0 = 12345678901234567890ULL;
unsigned long long tester1 = 0xffffffffffffffff;
char *ulltoa(char *buf, unsigned long long val)
{
char tmp[0x20];
char *cp = tmp;
char *rp = buf;
do {
*cp++ = (char) (val%10ULL) + '0';
val /= 10ULL;
} while (val);
do {
*buf++ = *(--cp);
} while (cp != tmp);
*buf = 0x00;
return rp;
}
char *lltoa(char *buf, long long val)
{
char *cp = buf;
if(val < 0) {
*cp++ = (char) '-';
val = ~val + 1LL;
}
(void) ulltoa(cp, (unsigned long)val);
return buf;
}
int main()
{
char buf[0x100];
printf("%llu\n", 0ULL);
printf("%llu\n", tester0);
printf("%llu\n", tester1);
printf("%s\n", ulltoa(buf, 0ULL));
printf("%s\n", ulltoa(buf, tester0));
printf("%s\n", ulltoa(buf, tester1));
printf("%s\n", lltoa(buf, tester1));
return 0;
}
Cheers,
Dick Johnson
Penguin : Linux version 2.4.24 on an i686 machine (797.90 BogoMips).
Note 96.31% of all statistics are fiction.
next prev parent reply other threads:[~2004-02-11 15:21 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-02-11 12:49 sting sting
2004-02-11 13:35 ` wdebruij
2004-02-11 13:48 ` Maciej Zenczykowski
2004-02-11 14:04 ` vda
2004-02-11 15:58 ` Maciej Zenczykowski
2004-02-11 19:41 ` H. Peter Anvin
2004-02-11 20:32 ` Måns Rullgård
2004-02-11 21:46 ` Chris Friesen
2004-02-11 22:38 ` Timothy Miller
2004-02-11 22:23 ` Andreas Schwab
2004-02-11 23:11 ` Måns Rullgård
2004-02-11 23:53 ` H. Peter Anvin
2004-02-11 16:59 ` Dick Streefland
2004-02-11 14:03 ` Måns Rullgård
2004-02-11 14:15 ` wdebruij
2004-02-11 15:23 ` Richard B. Johnson [this message]
2004-02-13 0:26 ` Peter Chubb
2004-02-11 13:54 Bart Hartgers
2004-02-11 14:04 ` YOSHIFUJI Hideaki / 吉藤英明
2004-02-11 14:13 ` Andreas Schwab
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.LNX.4.53.0402111021160.18798@chaos \
--to=root@chaos.analogic.com \
--cc=linux-kernel@vger.kernel.org \
--cc=wdebruij@dds.nl \
--cc=zstingx@hotmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®