Re: c question: *printf'ing arrays

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Alexander Best <alexbestms@...>
Cc: <rick-freebsd2008@...>, <freebsd-hackers@...>
Date: Saturday, July 4, 2009 - 2:59 am

On Wed, 01 Jul 2009 00:06:05 +0200 (CEST), Alexander Best <alexbestms@math.uni-muenster.de> wrote:

...


Note that %x will only print *one* digit for values smaller than 16,
i.e. printf("%x", 10) => "a", so it may be useful to use "%02x" instead.


For multi-byte fields, it makes sense to print "0x" first and then
iterate.  For single-byte values, it's probably a tiny bit faster to go
only _once_ through for *printf() family formatter, i.e.:

-     fprintf(stderr, "\nFixed Value: 0x");
-     fprintf(stderr, "%x", hdr->fixed_val);
+     fprintf(stderr, "\nFixed Value: 0x%x", hdr->fixed_val);

Another nit that I noticed is that your last line doesn't end with "\n":


Some terminal setups will *not* output the last line if it does not
finish properly with a "\n", so it may be worth editing the code to
avoid the "\nXXX" format idiom, and go for a format style that puts
"\n" at the _end_ of output lines:

    fprintf(stderr, "Nintendo Logo: 0x");
    for (i = 0; i < sizeof(hdr->nintendo_logo); i++)
             fprintf(stderr, "%02x", hdr->nintendo_logo[i]);
    fprintf(stderr, "\n");

    fprintf(stderr, "Fixed Value: 0x%02x\n", hdr->fixed_val);

_______________________________________________
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
c question: *printf'ing arrays, Alexander Best, (Tue Jun 30, 12:12 pm)
Re: c question: *printf'ing arrays, Tom Evans, (Tue Jun 30, 12:49 pm)
Re: c question: *printf'ing arrays, Alexander Best, (Tue Jun 30, 1:10 pm)
Re: c question: *printf'ing arrays, Igor Mozolevsky, (Tue Jun 30, 1:16 pm)
Re: c question: *printf'ing arrays, Igor Mozolevsky, (Tue Jun 30, 2:00 pm)
Re: c question: *printf'ing arrays, Carlos A. M. dos Santos, (Thu Jul 2, 2:10 pm)
Re: c question: *printf'ing arrays, Alexander Best, (Tue Jun 30, 2:03 pm)
Re: c question: *printf'ing arrays, Rick C. Petty, (Tue Jun 30, 2:11 pm)
Re: c question: *printf'ing arrays, Igor Mozolevsky, (Tue Jun 30, 2:19 pm)
Re: c question: *printf'ing arrays, Rick C. Petty, (Tue Jun 30, 5:02 pm)
Re: c question: *printf'ing arrays, Alexander Best, (Wed Jul 8, 6:43 pm)
Re: c question: *printf'ing arrays, Giorgos Keramidas, (Sat Jul 4, 2:51 am)
Re: c question: *printf'ing arrays, Alexander Best, (Tue Jun 30, 2:21 pm)
Re: c question: *printf'ing arrays, Giorgos Keramidas, (Sat Jul 4, 2:59 am)
Re: c question: *printf'ing arrays, Alexander Best, (Tue Jun 30, 8:01 pm)
Re: c question: *printf'ing arrays, Stephen Montgomery-Smith, (Tue Jun 30, 3:17 pm)
Re: c question: *printf'ing arrays, Carlos A. M. dos Santos, (Wed Jul 1, 9:48 pm)
Re: c question: *printf'ing arrays, Alexander Best, (Tue Jun 30, 1:32 pm)
Re: c question: *printf'ing arrays, Alexander Best, (Tue Jun 30, 6:06 pm)
Re: c question: *printf'ing arrays, Carlos A. M. dos Santos, (Wed Jul 1, 8:39 pm)
Re: c question: *printf'ing arrays, Igor Mozolevsky, (Sat Jul 4, 4:52 am)
Re: c question: *printf'ing arrays, Alfred Perlstein, (Tue Jun 30, 6:54 pm)
Re: c question: *printf'ing arrays, Dag-Erling Smørgrav, (Thu Jul 2, 12:03 pm)