Date: Fri, 26 Feb 1999 20:57:44 +0000 From: Andy Doran <ad@psn.ie> To: "Alton, Matthew" <Matthew.Alton@anheuser-busch.com> Cc: "'Hackers@FreeBSD.ORG'" <Hackers@FreeBSD.ORG>, "Ladendorf, Matt" <Matt.Ladendorf@anheuser-busch.com> Subject: Re: printf wierdness Message-ID: <36D70AC8.A862B8C0@psn.ie> References: <BED2E68B5FB4D21193C90008C7C56836564C53@STLABCEXG012>
next in thread | previous in thread | raw e-mail | index | archive | help
printf() is treating the %llu type as an unsigned long (%lu), so it's taking the value for %s from the second 32-bits in 'foo'. Check the printf(3) manpage. Andy. "Alton, Matthew" wrote: > > Why is this happening? > > $ vi foo.c > > #include <stdio.h> > > int > main(void) > { > unsigned long long int foo = 0; > char *bar = "Hidely Ho!"; > > (void)printf("%llu %s\n", foo, bar); > (void)printf("%s %llu\n", bar, foo); > > return 0; > } > > ~ > ~ > ~ > ~ > ~ > ~ > ~ > ~ > ~ > foo.c: 14 lines, 196 characters. > $ make foo > cc foo.c -o foo > $ ./foo > 0 (null) > Hidely Ho! 0 > $ > > Matthew Alton > Computer Services - UNIX Systems Administration > (314)632-6644 matthew.alton@anheuser-busch.com > alton@plantnet.com > > To Unsubscribe: send mail to majordomo@FreeBSD.org > with "unsubscribe freebsd-hackers" in the body of the message To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?36D70AC8.A862B8C0>