home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / c / 12984 < prev    next >
Encoding:
Internet Message Format  |  1992-08-30  |  1.4 KB

  1. Path: sparky!uunet!ferkel.ucsb.edu!taco!gatech!bloom-beacon!eru.mt.luth.se!lunic!sunic!mcsun!sun4nl!and!jos
  2. From: jos@and.nl (Jos Horsmeier)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: printf question
  5. Message-ID: <3361@dozo.and.nl>
  6. Date: 30 Aug 92 14:25:57 GMT
  7. References: <kimcm.714943581@login.dkuug.dk> <1226@pascal.einstein.eds.com> <RICHARD.92Aug30153124@CLYDE.ttt.kth.se>
  8. Organization: AND Software BV Rotterdam
  9. Lines: 27
  10.  
  11. In article <RICHARD.92Aug30153124@CLYDE.ttt.kth.se> RICHARD@CLYDE.ttt.kth.se writes:
  12. |In article <kimcm.714943581@login.dkuug.dk> kimcm@login.dkuug.dk (Kim Chr. Madsen) writes:
  13. ||   #define HDPI "4" /* Hex Digits Per Int */
  14. ||
  15. ||       printf( "%0" HDPI "x\n", address );
  16. ||
  17. ||   And if you have read this far, you surely won't mind one more irrelevant
  18. ||   remark ;-)  Using this syntax on the original problem will save you some
  19. ||   time because the format is evaluated at compile time instead of run time.
  20. |
  21. |Huh????? Since when is the format evaluated at compile time? I've never
  22. |seen that done!
  23.  
  24. The contents of the format string isn't evaluated at compile time but,
  25. in this case, the pre-processor concatenates the constant strings after
  26. macro replacement. The evaluation goes like this:
  27.  
  28. 1:       printf( "%0" HDPI "x\n", address );
  29. 2:         printf( "%0" "4" "x\n", address );
  30. 3:         printf( "%04x\n", address );
  31.  
  32. And that was exactly what the original poster had in mind; all done during
  33. compile time ...
  34.  
  35. kind regards,
  36.  
  37. Jos aka jos@and.nl
  38.