Subject: misc/24383: Bad example in ``style'' WRT printing 64 bit values
To: None <>
From: Christian Biere <>
List: netbsd-bugs
Date: 02/10/2004 17:24:10
>Number:         24383
>Category:       misc
>Synopsis:       Bad example in ``style'' WRT printing 64 bit values
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    misc-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Tue Feb 10 17:25:00 UTC 2004
>Originator:     Christian Biere
>Release:        NetBSD 1.6ZH
System: NetBSD cyclonus 1.6ZH NetBSD 1.6ZH (STARSCREAM) #0: Fri Feb 6 00:16:58 CET 2004 root@cyclonus:/usr/src/sys/arch/i386/compile/STARSCREAM i386

/usr/share/misc/style suggests to use a cast to "long long" to print
64 bit quantities. AFAIK, (long long) is a GNU extension. At least, it's
not supported by many other compilers. C99 defined standard macros for
the various integer types to be used with printf. Even if a compiler or
the platform lacks support for these or uses its own extension, you can
easily work around this by declaring the C99 macros. You cannot typedef
"long long" or "#define 'long long' uint64_t", so you would have to check
and correct every occurence of "long long". Further, assuming "long long"
being a 64 bit integer is just wrong. The GCC definition is "double as
long (wide) as long" so it can be a 128 bit integer as well.


Index: style
RCS file: /cvsroot/src/share/misc/style,v
retrieving revision 1.27
diff -u -r1.27 style
--- style	2003/09/27 21:17:31	1.27
+++ style	2004/02/10 17:14:14
@@ -362,9 +362,9 @@
 		err(1, "Unable to stat %s", p);
-	 * To printf 64 bit quantities, use %ll and cast to (long long).
+	 * To printf 64 bit quantities, use PRid64 and cast to (int64_t).
-	printf("The size of %s is %lld\n", p, (long long)sb->st_size);
+	printf("The size of %s is %"PRid64"\n", p, (int64_t)sb->st_size);