🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #2767

Re: Preprocessor question

#2767
From: Stephen Vinoski
Date: Thu, 18 Apr 1991 18:39
29 lines
1518 bytes
In article <AHUTTUNE.91Feb16230548@silver-surfer.hut.fi> ahuttune@niksula.hut.fi (Ari Juhani Huttunen) writes:
>I would like to do the following or something similar:
>
>#define BLOCK_SIZE 1024
>
>char *message = "The block size is " # BLOCK_SIZE " bytes.";
>
>I need the result: "The block size is 1024 bytes."
>
>I know what I am doing wrong, but HOW should I do it? These alternatives
>are no good:
>	- #define BLOCK_SIZE_STRING "1024"
>	- char *message = "The block size is 1024 bytes.";

How about:

#define BLOCK_SIZE 1024
#define REALSTR(x) #x
#define STR(x) REALSTR(x)

char *message = "The block size is " STR(BLOCK_SIZE) " bytes.";



-steve
| Steve Vinoski  (508)256-0176 x5904       | Internet: vinoski@apollo.hp.com  |
| HP Apollo Division, Chelmsford, MA 01824 | UUCP: ...!apollo!vinoski         |
| "The price of knowledge is learning how little of it you yourself harbor."  |
|                                                    - Tom Christiansen       |
Technical Details
Message-ID: <510d1d6f.20b6d@apollo.HP.COM>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!apollo!vinoski
References: <AHUTTUNE.91Feb16230548@silver-surfer.hut.fi>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!apollo!vinoski
From: vinoski@apollo.HP.COM (Stephen Vinoski)
Newsgroups: comp.std.c
Subject: Re: Preprocessor question
Message-ID: <510d1d6f.20b6d@apollo.HP.COM>
Date: 18 Apr 91 18:39 GMT
References: <AHUTTUNE.91Feb16230548@silver-surfer.hut.fi>
Sender: root@apollo.HP.COM
Reply-To: vinoski@apollo.HP.COM (Stephen Vinoski)
Distribution: comp
Organization: Hewlett-Packard Apollo Division - Chelmsford, MA
Lines: 29