home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / c / 13104 < prev    next >
Encoding:
Internet Message Format  |  1992-09-02  |  805 b 

  1. Path: sparky!uunet!mcsun!uknet!acorn!jcoxhead
  2. From: jcoxhead@acorn.co.uk (Jonathan Coxhead)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: printf question
  5. Message-ID: <18260@acorn.co.uk>
  6. Date: 2 Sep 92 11:07:05 GMT
  7. References: <1992Sep01.214725.6334@ima.isc.com>
  8. Sender: jcoxhead@acorn.co.uk
  9. Organization: Acorn Computers Ltd, Cambridge, England
  10. Lines: 23
  11.  
  12.  
  13.    In article "Re: printf question" karl@ima.isc.com (Karl Heuer) writes
  14. parenthetically
  15.  
  16.          The C preprocessor has no way to evaluate-and-stringise a constant
  17.       expression.
  18.  
  19. but it does!
  20.  
  21.       #define STR_(s) #s
  22.       #define STR(s)  STR_ (s)
  23.  
  24.       #define WIDTH 8
  25.  
  26.       printf ("%" STR (WIDTH) "x", n);
  27.  
  28.    Easy. I keep the first two lines in a central place for whenever I need
  29. them, along with other useful stuff.
  30.  
  31.    /|
  32.   (_|/
  33.    /|
  34.   (_/
  35.