<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"><channel><title>mikeash.com pyblog/friday-qa-2009-07-17-format-strings-tips-and-tricks.html comments</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-07-17-format-strings-tips-and-tricks.html#comments</link><description>mikeash.com Recent Comments</description><lastBuildDate>Sun, 10 May 2026 04:37:58 GMT</lastBuildDate><generator>PyRSS2Gen-1.0.0</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>Peter N Lewis - 2009-07-27 17:21:22</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-07-17-format-strings-tips-and-tricks.html#comments</link><description>blockquote&amp;gt;For example, here is a convenient way to turn a FourCharCode into an NSString:
&lt;br /&gt;&amp;lt;pre&amp;gt;    uint32_t valSwapped = CFSwapInt32HostToBig(fcc); // FCCs are stored backwards on Intel
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;NSString *str = [NSString stringWithFormat:@"%.4s", &amp;amp;valSwapped;];
&lt;br /&gt;&amp;lt;/pre&amp;gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;While %.Ns is a clever trick, this wont actually work in general because OSTypes are defined to be in MacRoman the character set where stringWithFormat uses the system encoding which may be different.
&lt;br /&gt;
&lt;br /&gt;Instead you need to use something like:
&lt;br /&gt;&lt;div class="blogcommentquote"&gt;&lt;div class="blogcommentquoteinner"&gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;NSData* data = [NSData dataWithBytes:&amp;amp;valSwapped length:sizeof(valSwapped)];
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return [[[NSString alloc]initWithData:data encoding:NSMacOSRomanStringEncoding] autorelease];
&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;
&lt;br /&gt;</description><guid isPermaLink="true">0d20eab644ddc38dd45ec0a8d3a450b5</guid><pubDate>Mon, 27 Jul 2009 17:21:22 GMT</pubDate></item><item><title>Adam Rosenfield - 2009-07-25 23:33:47</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-07-17-format-strings-tips-and-tricks.html#comments</link><description>The exact output of the %p specifier is implementation-defined; some implementations prepend a 0x to the output, some don't, some use uppercase, and some use lowercase.  If you want a guaranteed output format, you should do something like:
&lt;br /&gt;
&lt;br /&gt;printf("0x%08x\n", (uint32_t)ptr);
&lt;br /&gt;
&lt;br /&gt;And use llx instead of x for 64-bit systems.  Whenever you're printing out pointer values, 99.99% of the time you're debugging something, so you know the size of pointers on your platform.  Hence, it's ok to be lazy and ditch the pointer-to-integer cast entirely.
&lt;br /&gt;
&lt;br /&gt;I also strongly recommend always compiling with the -Wformat warning option (enabled with -Wall) with GCC -- it'll help you catch a lot of easy-to-miss errors often due to typos such as too many arguments, not enough arguments, mismatched format specifiers and arguments, etc.
&lt;br /&gt;
&lt;br /&gt;GCC also has a nifty `format' function attribute which you can use to tag any functions you write that are wrappers around printf/scanf (such as a custom logging function), and it can then check the arguments you pass to that -- see &lt;a href="http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html#index-g_t_0040code_007bformat_007d-function-attribute-2291"&gt;http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html#index-g_t_0040code_007bformat_007d-function-attribute-2291&lt;/a&gt; for more info.</description><guid isPermaLink="true">17236822017d3d67422628898b981f40</guid><pubDate>Sat, 25 Jul 2009 23:33:47 GMT</pubDate></item><item><title>mikeash - 2009-07-20 18:53:14</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-07-17-format-strings-tips-and-tricks.html#comments</link><description>Although strftime's strings look superficially like printf's, they are actually completely different and such do not count. You can argue about what is or is not a "format string", but in this article I was only discussing the ones used by printf and similar functions, and those must always be used with variable arguments (whether in the form of a ... argument or a va_list).</description><guid isPermaLink="true">044ffc7344db33e1c5e9cdf350250cce</guid><pubDate>Mon, 20 Jul 2009 18:53:14 GMT</pubDate></item><item><title>Gwynne Raskind - 2009-07-20 16:01:44</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-07-17-format-strings-tips-and-tricks.html#comments</link><description>I beg to differ that format strings are always used with variadic arguments. strftime(3) is the most obvious example.</description><guid isPermaLink="true">52d8695f28f6c36b4b1ceb5572ce9182</guid><pubDate>Mon, 20 Jul 2009 16:01:44 GMT</pubDate></item><item><title>Damien Sorresso - 2009-07-20 11:39:31</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-07-17-format-strings-tips-and-tricks.html#comments</link><description>Upon a re-read, you're right. I just misinterpreted the sentence the first time. </description><guid isPermaLink="true">4e04116367f1a7b3d257bab6a6bcb020</guid><pubDate>Mon, 20 Jul 2009 11:39:31 GMT</pubDate></item><item><title>mikeash - 2009-07-19 09:27:04</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-07-17-format-strings-tips-and-tricks.html#comments</link><description>I must disagree about the wording. A google search for "is always used with" reveals that the phrase is normally used in the way I did. In other words, "X is always used with Y" means that X implies Y, but not that Y implies X.
&lt;br /&gt;
&lt;br /&gt;Thanks for the article idea, I'll put it on my list.</description><guid isPermaLink="true">fcd4c3dd7f12cadcbd28dc0463be8aaa</guid><pubDate>Sun, 19 Jul 2009 09:27:04 GMT</pubDate></item><item><title>Damien Sorresso - 2009-07-19 03:27:42</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-07-17-format-strings-tips-and-tricks.html#comments</link><description>Tiny nitpick.
&lt;br /&gt;
&lt;br /&gt;&lt;div class="blogcommentquote"&gt;&lt;div class="blogcommentquoteinner"&gt;Format strings are always used with a function (or method) that takes variable arguments. This is important for several reasons.&lt;/div&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;This sentence makes it seem like all functions which take variable arguments also take format strings. I know that's not what you meant, but a better wording would be "Functions or methods which take format strings always take a variable number of arguments."
&lt;br /&gt;
&lt;br /&gt;That brings up another good Friday Q&amp;amp;A idea. Maybe you should cover implementing a function that uses variadic arguments, some of the pitfalls in doing so, etc. (Maybe even touch on variadic arguments in preprocessor macros.)
&lt;br /&gt;
&lt;br /&gt;Also, Jean-Daniel, NULL and a null pointer are different. A null pointer is a pointer which has been assigned the value NULL. NULL itself is just 0.
&lt;br /&gt;
&lt;br /&gt;Other fun Mac OS X-specific format string tidbits...
&lt;br /&gt;* NSString and CFString may be constructed with a format string, and you can specify "%@" to print the description of a Cocoa or CF object, respectively.
&lt;br /&gt;* The syslog(3) API allows you to specify "%m" to print the current errno. This does not require a corresponding argument in the argument list, so use with care.</description><guid isPermaLink="true">fb2a629553fc6387631150d73b885028</guid><pubDate>Sun, 19 Jul 2009 03:27:42 GMT</pubDate></item><item><title>mikeash - 2009-07-18 19:04:20</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-07-17-format-strings-tips-and-tricks.html#comments</link><description>Conceptually nil and Nil are those types, but practically they don't have to be. In the absence of a real Objective-C language spec it's hard to say exactly what they can or can't be, but we can probably consider them to be equivalent to NULL.
&lt;br /&gt;
&lt;br /&gt;However, it's not a problem for things like NSError **. The fact that NULL (and nil and Nil) can be an integer 0 is only a problem when using varargs. For explicitly typed parameters, the 0 will be converted to the null pointer.</description><guid isPermaLink="true">5b2fc4adc91f3c6643a640169b287eec</guid><pubDate>Sat, 18 Jul 2009 19:04:20 GMT</pubDate></item><item><title>Jordy/Jediknil - 2009-07-18 15:41:06</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-07-17-format-strings-tips-and-tricks.html#comments</link><description>Huh. I really thought nil was (id)(NULL) and Nil was (Class)(NULL). That would have made everything a little more convenient.
&lt;br /&gt;
&lt;br /&gt;Well, except that a Class is a valid id. And that we use NULL all over the place (NSError **, anyone?).</description><guid isPermaLink="true">248d894e5ad56cfa5c0f30ec4b3faef3</guid><pubDate>Sat, 18 Jul 2009 15:41:06 GMT</pubDate></item><item><title>Peter Bierman - 2009-07-18 08:36:44</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-07-17-format-strings-tips-and-tricks.html#comments</link><description>Good tips! A suggestion: mention the "solution" for the non-constant format strings vulnerability where you wrote about it. printf("%s", someString);</description><guid isPermaLink="true">8ea1f6662ed23cbd73a663f6fe087915</guid><pubDate>Sat, 18 Jul 2009 08:36:44 GMT</pubDate></item><item><title>Vincent Gable - 2009-07-18 07:08:33</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-07-17-format-strings-tips-and-tricks.html#comments</link><description>Thanks mikeash, that's excellent information!
&lt;br /&gt;
&lt;br /&gt;Something that's been very helpful to me when printf-debugging is using macros to print variables without ever having to mess with format strings. It turns out that 90% of the time I can just say `LOG_ID(name)` and the "name = Vincent" information is all I needed.
&lt;br /&gt;Details here:
&lt;br /&gt;&lt;a href="http://vgable.com/blog/2008/08/05/simpler-logging-2/"&gt;http://vgable.com/blog/2008/08/05/simpler-logging-2/&lt;/a&gt;
&lt;br /&gt;
&lt;br /&gt;Also, Dave Dribin created an excellent DDToNSString() function that can automagically convert a C-type into an NSSString:
&lt;br /&gt;&lt;a href="http://www.dribin.org/dave/blog/archives/2008/09/22/convert_to_nsstring/"&gt;http://www.dribin.org/dave/blog/archives/2008/09/22/convert_to_nsstring/&lt;/a&gt;
&lt;br /&gt;
&lt;br /&gt;I've been using a modified DDToNSString() in a LOG_EXPR() macro that (mostly) Just Works no matter what type it's given. Once I've worked out a few more kinks, and understand the esoteric build settings it needs, I'll write something up on it.</description><guid isPermaLink="true">6e33477b233f8272136e50525720a949</guid><pubDate>Sat, 18 Jul 2009 07:08:33 GMT</pubDate></item><item><title>mikeash - 2009-07-18 03:54:06</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-07-17-format-strings-tips-and-tricks.html#comments</link><description>Again, size is not what matters, only type. There is no guarantee that the integer 0 will be received correctly if the other side is expecting a pointer, even if they are both the same size. Mixing and matching will work on most systems but could result in bad data or even a crash on some.
&lt;br /&gt;
&lt;br /&gt;Unless POSIX also defines NULL to be a "null pointer" then I'm afraid that definition isn't relevant to the question. All this definition means is that NULL is not necessarily a null pointer.</description><guid isPermaLink="true">58fdd0ff1c26794c921ee3e862943505</guid><pubDate>Sat, 18 Jul 2009 03:54:06 GMT</pubDate></item><item><title>Jean-Daniel Dupas - 2009-07-18 03:47:52</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-07-17-format-strings-tips-and-tricks.html#comments</link><description>Doo. I read again the spec and you're right. Nothing tells that sizeof(null pointer constant) == sizeof(void *)
&lt;br /&gt;
&lt;br /&gt;But I managed to find a interesting sentence in POSIX though:
&lt;br /&gt;
&lt;br /&gt;3.244 Null Pointer
&lt;br /&gt;
&lt;br /&gt;The value that is obtained by converting the number 0 into a pointer; for example, (void *) 0. The C language guarantees that this value does not match that of any legitimate pointer, so it is used by many functions that return pointers to indicate an error.
&lt;br /&gt;
&lt;br /&gt;&lt;a href="http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap03.html"&gt;http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap03.html&lt;/a&gt;
&lt;br /&gt;
&lt;br /&gt;</description><guid isPermaLink="true">24ef26350fbe6088960a343fce163bf2</guid><pubDate>Sat, 18 Jul 2009 03:47:52 GMT</pubDate></item><item><title>mikeash - 2009-07-18 02:08:19</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-07-17-format-strings-tips-and-tricks.html#comments</link><description>Yes, on current OS versions you can do all sorts of things. You can use %lx to print pointers, you can use %ld to print size_t and NSInteger and many other types, and in general you can just look up what the sizes are and use a specifier which mostly matches. Doesn't mean it's a good idea.</description><guid isPermaLink="true">91adb5f84f1fcb72497e446811e252ff</guid><pubDate>Sat, 18 Jul 2009 02:08:19 GMT</pubDate></item><item><title>Peter Hosey - 2009-07-18 01:35:08</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-07-17-format-strings-tips-and-tricks.html#comments</link><description>So you are talking about hypothetical future OS versions, then. As you say, these are good to keep in mind.</description><guid isPermaLink="true">8b865a6edf1a845233e61115db50b2eb</guid><pubDate>Sat, 18 Jul 2009 01:35:08 GMT</pubDate></item><item><title>mikeash - 2009-07-18 01:19:15</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-07-17-format-strings-tips-and-tricks.html#comments</link><description>&lt;b&gt;Peter Hosey:&lt;/b&gt; "Always the same size" is completely irrelevant. Nothing in the standard says that you can pass an integer of one type and retrieve it using a different integer type of the same size, even if this works on most implementations.
&lt;br /&gt;
&lt;br /&gt;You are correct that using &lt;code&gt;%ld&lt;/code&gt; will correctly print an NSInteger on all &lt;i&gt;current&lt;/i&gt; Cocoa architectures. And two years ago, pointers were always 32-bit on all &lt;i&gt;current&lt;/i&gt; Cocoa architectures. Four years ago, integers were always big-endian on all &lt;i&gt;current&lt;/i&gt; Cocoa architectures. If you write your code to depend on today's assumptions, your code will break tomorrow.
&lt;br /&gt;
&lt;br /&gt;Numbered argument specifiers are not part of the C standard but they are part of the POSIX standard, so unless you need your code to be portable to non-POSIX platforms you can depend on them to exist. See &lt;a href="http://www.opengroup.org/onlinepubs/000095399/functions/printf.html"&gt;http://www.opengroup.org/onlinepubs/000095399/functions/printf.html&lt;/a&gt;
&lt;br /&gt;
&lt;br /&gt;However my example which mixes numbered specifiers and non-numbered specifiers is not supported at all. It's an all-or-nothing thing.
&lt;br /&gt;
&lt;br /&gt;&lt;b&gt;Jean-Daniel Dupas:&lt;/b&gt; I don't believe you're correct that C99 defines NULL as a pointer. The C99 standard is available here: &lt;a href="http://www.open-std.org/JTC1/SC22/wg14/www/docs/n1124.pdf"&gt;http://www.open-std.org/JTC1/SC22/wg14/www/docs/n1124.pdf&lt;/a&gt;
&lt;br /&gt;
&lt;br /&gt;The relevant passages are this:
&lt;br /&gt;
&lt;br /&gt;&lt;div class="blogcommentquote"&gt;&lt;div class="blogcommentquoteinner"&gt;An integer constant expression with the value 0, or such an expression cast to type void *, is called a null pointer constant.&lt;/div&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;And:
&lt;br /&gt;
&lt;br /&gt;&lt;div class="blogcommentquote"&gt;&lt;div class="blogcommentquoteinner"&gt;The macro NULL is defined in &amp;lt;stddef.h&amp;gt; (and other headers) as a null pointer constant; see 7.17.&lt;/div&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;These both appear on page 47. Thus NULL can be correctly defined as 0, (void *)0, (3 - 3), (void *)(42/43), etc. No statement is made about it being required to be a pointer type as far as I can see.</description><guid isPermaLink="true">0ae01c7b846422ec5b33f787dc10f982</guid><pubDate>Sat, 18 Jul 2009 01:19:15 GMT</pubDate></item><item><title>Peter Hosey - 2009-07-18 01:15:26</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-07-17-format-strings-tips-and-tricks.html#comments</link><description>Jean-Daniel Dupas:
&lt;br /&gt;
&lt;br /&gt;&lt;div class="blogcommentquote"&gt;&lt;div class="blogcommentquoteinner"&gt;... no, it does not always have the same size on the current OS X version.&lt;/div&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;That's not what I said. I said it always has the same size &lt;b&gt;as long&lt;/b&gt; on current Mac OS X.</description><guid isPermaLink="true">f4109c4b2a7bf20b607fdc03796c52e3</guid><pubDate>Sat, 18 Jul 2009 01:15:26 GMT</pubDate></item><item><title>Jose Vazquez - 2009-07-18 00:17:09</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-07-17-format-strings-tips-and-tricks.html#comments</link><description>Thank you! Interesting, to find out that after so many years of using it there were still so many useful tricks to learn. I have managed to bend printf to my will, but now I have a deeper understanding of it. The Type Promotion stuff in particular just dispelled a lot of magic. </description><guid isPermaLink="true">d8a6731be613c36b7945f73c6c99b051</guid><pubDate>Sat, 18 Jul 2009 00:17:09 GMT</pubDate></item><item><title>Jean-Daniel Dupas - 2009-07-18 00:08:14</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-07-17-format-strings-tips-and-tricks.html#comments</link><description>@Peter Hosey : NSInteger is defined as a 32 bit integer on 32 bit arch, and 64 bits integer on 64 bit arch. So no, it does not always have the same size on the current OS X version.
&lt;br /&gt;
&lt;br /&gt;&lt;div class="blogcommentquote"&gt;&lt;div class="blogcommentquoteinner"&gt;Yes, that means all of the code out there which looks like this is, strictly speaking, wrong:
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[NSArray arrayWithObjects:a, b, c, nil];&lt;/div&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;It depends what you mean by "strictly". The C99 standard define NULL as a pointer, so this code is correct as long as you use a C99 compliant compiler.</description><guid isPermaLink="true">cf41212b0140db90207512f350b89b28</guid><pubDate>Sat, 18 Jul 2009 00:08:14 GMT</pubDate></item><item><title>foobaz - 2009-07-17 23:52:53</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-07-17-format-strings-tips-and-tricks.html#comments</link><description>To print a size_t, you can also use %zu, like this:
&lt;br /&gt;&lt;div class="blogcommentquote"&gt;&lt;div class="blogcommentquoteinner"&gt;NSLog(@"lod == %zu", layer.levelsOfDetail);&lt;/div&gt;&lt;/div&gt;</description><guid isPermaLink="true">7850f203c92f5ae134b72ea7a8d2bd84</guid><pubDate>Fri, 17 Jul 2009 23:52:53 GMT</pubDate></item><item><title>Peter Hosey - 2009-07-17 23:42:04</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-07-17-format-strings-tips-and-tricks.html#comments</link><description>Yargh, proofreading fail.
&lt;br /&gt;
&lt;br /&gt;&lt;div class="blogcommentquote"&gt;&lt;div class="blogcommentquoteinner"&gt;As of Mac OS X, ...&lt;/div&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;I mean Mac OS X 10.5.7.</description><guid isPermaLink="true">1107e8c55d1a359ced1f9e189a87d382</guid><pubDate>Fri, 17 Jul 2009 23:42:04 GMT</pubDate></item><item><title>Peter Hosey - 2009-07-17 23:41:22</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-07-17-format-strings-tips-and-tricks.html#comments</link><description>Oh, now I see the problem with the dollar sign feature. Thanks, Dave. Still an extension, though.</description><guid isPermaLink="true">1d18738444702a90d7ffddf15bf248b5</guid><pubDate>Fri, 17 Jul 2009 23:41:22 GMT</pubDate></item><item><title>Peter Hosey - 2009-07-17 23:40:17</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-07-17-format-strings-tips-and-tricks.html#comments</link><description>&lt;div class="blogcommentquote"&gt;&lt;div class="blogcommentquoteinner"&gt;For ... NSInteger you need to get a little cleverer. You can't use %d because [it] might be bigger than an int. You can't use %ld or %lld because [it] might be smaller than those, and type promotion doesn't carry over. [It] could even be bigger than those.&lt;/div&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;Are you talking about a hypothetical future version of Mac OS X? As of Mac OS X, it's always the same size as a long on all currently-supported architectures. I believe this goes for the iPhone as well.
&lt;br /&gt;
&lt;br /&gt;&lt;div class="blogcommentquote"&gt;&lt;div class="blogcommentquoteinner"&gt;NULL can legally just be a #define to 0...&lt;/div&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;Well, it can be. In C++ and Objective-C++, it may be. But in C and Objective-C, it isn't. See the definitions of __DARWIN_NULL in &amp;lt;sys/_types.h&amp;gt;, Nil and nil in &amp;lt;objc/objc.h&amp;gt;, and NULL everywhere that matters.
&lt;br /&gt;
&lt;br /&gt;This is mainly valid as a portability concern: Some other operating system may be more free-wheeling in its headers' definition of NULL, and *then*, it's worth being careful with how you use NULL.
&lt;br /&gt;
&lt;br /&gt;&lt;div class="blogcommentquote"&gt;&lt;div class="blogcommentquoteinner"&gt;You can actually have any specifier use any argument. This is done by adding $n to the format specifier, where n is the argument number to print.&lt;/div&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;That's an extension; it's not part of the C99 standard. Moreover, it doesn't even work with printf; it's only available in Core Foundation. (And you forgot a \n in your format string.)
&lt;br /&gt;</description><guid isPermaLink="true">e02719465186ea1c9885a22350c37f90</guid><pubDate>Fri, 17 Jul 2009 23:40:17 GMT</pubDate></item><item><title>mikeash - 2009-07-17 23:22:11</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-07-17-format-strings-tips-and-tricks.html#comments</link><description>How embarrassing! Thanks for letting me know. I've fixed up the article.</description><guid isPermaLink="true">abbfe104f3c4c4e7373d81596bfa593e</guid><pubDate>Fri, 17 Jul 2009 23:22:11 GMT</pubDate></item><item><title>Dave - 2009-07-17 23:17:38</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-07-17-format-strings-tips-and-tricks.html#comments</link><description>Very useful, thank you!  The only comment I have is about using random access arguments.  You have:
&lt;br /&gt;
&lt;br /&gt;printf("a = %$2d  b = %$1d", b, a);
&lt;br /&gt;
&lt;br /&gt;When in reality it should be:
&lt;br /&gt;
&lt;br /&gt;printf("a = %2$d  b = %1$d", b, a);
&lt;br /&gt;
&lt;br /&gt;The dollar sign should be &lt;i&gt;after&lt;/i&gt; the digit.
&lt;br /&gt;
&lt;br /&gt;Cheers,
&lt;br /&gt;
&lt;br /&gt;Dave</description><guid isPermaLink="true">128a8b188beae5240bb38577273698a8</guid><pubDate>Fri, 17 Jul 2009 23:17:38 GMT</pubDate></item><item><title>Padraig Brady - 2009-07-17 23:03:20</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-07-17-format-strings-tips-and-tricks.html#comments</link><description>Good info thanks! I find the man pages on linux at least a bit hard to parse, so I created a &amp;lt;a href="&lt;a href="http://www.pixelbeat.org/programming/gcc/format_specs.html&amp;amp;gt"&gt;http://www.pixelbeat.org/programming/gcc/format_specs.html&amp;gt;&lt;/a&gt;;printf crib sheet&amp;lt;/a&amp;gt;. I also wrote some notes for printing variable sized ints since they're a common source of confusion: &lt;a href="http://www.pixelbeat.org/programming/gcc/int_types/"&gt;http://www.pixelbeat.org/programming/gcc/int_types/&lt;/a&gt;
&lt;br /&gt;</description><guid isPermaLink="true">898ec370e790f616e064af3e2de943c3</guid><pubDate>Fri, 17 Jul 2009 23:03:20 GMT</pubDate></item></channel></rss>
