bringo@locus.com (Bob Ringo) (01/31/91)
Hi, this is probably a simple task, but I haven't figured it out. I'd like to do the following: #define A "Good" #define B "Morning" #define C /* the concatenation of A and B */ --I tried the following, but it didn't work. #define paste(x,y) x ## y #define A "Good" #deifne B "Morning" #define C paste(A,B) Any Hints? -- Bob Ringo Locus Computing Corporation bringo@locus.com
volpe@camelback.crd.ge.com (Christopher R Volpe) (02/01/91)
In article <1991Jan30.232740.1697267@locus.com>, bringo@locus.com (Bob Ringo) writes: |>Hi, this is probably a simple task, but I haven't figured it out. |>I'd like to do the following: |> |>#define A "Good" |>#define B "Morning" |>#define C /* the concatenation of A and B */ |> |> |>--I tried the following, but it didn't work. |> |>#define paste(x,y) x ## y |>#define A "Good" |>#deifne B "Morning" |>#define C paste(A,B) Is there any reason you can't rely on the compiler's automatic concatenation of adjacent string literals? For example, printf(A B); will print "GoodMorning". |>Bob Ringo |>Locus Computing Corporation |>bringo@locus.com ================== Chris Volpe G.E. Corporate R&D volpecr@crd.ge.com
rjohnson@shell.com (Roy Johnson) (02/01/91)
In article <1991Jan30.232740.1697267@locus.com> bringo@locus.com (Bob Ringo) writes: >I'd like to do the following: >#define A "Good" >#define B "Morning" >#define C>/* the concatenation of A and B */ In ANSI, you could just do #define C A B because juxtaposition concatenates strings. In Sun C, there is no good way to do this. -- ======= !{sun,psuvax1,bcm,rice,decwrl,cs.utexas.edu}!shell!rjohnson ======= "If he exploded, all of Manhattan would be talking in high, squeaky voices for months!" "Cool." -- When I Was Short Roy Johnson, Shell Development Company
gwyn@smoke.brl.mil (Doug Gwyn) (02/01/91)
In article <1991Jan30.232740.1697267@locus.com> bringo@locus.com (Bob Ringo) writes: >Hi, this is probably a simple task, but I haven't figured it out. >I'd like to do the following: >#define A "Good" >#define B "Morning" >#define C /* the concatenation of A and B */ This is an ill-defined requirement.. >--I tried the following, but it didn't work. >#define paste(x,y) x ## y >#define A "Good" >#deifne B "Morning" >#define C paste(A,B) I suppose for your purposes the following would suffice: #define A "Good" #define B "Morning" #define C (A B) Note that string-literal splicing is a new feature with ANSI C and that it occurs AFTER the preprocessing phases.
browns@iccgcc.decnet.ab.com (Stan Brown) (02/02/91)
In article <1991Jan30.232740.1697267@locus.com>, bringo@locus.com (Bob Ringo) writes: > Hi, this is probably a simple task, but I haven't figured it out. > I'd like to do the following: > > #define A "Good" > #define B "Morning" > #define C /* the concatenation of A and B */ Assuming A and B will always be literal strings, you can use either #define C A B or #define C(x,y) x y When two character strings are separated only by white space, they aare always concatenated. Hey--this is all my opinion, nobody else's. Rely on it at your peril. email: browns@ab.com -or- browns@iccgcc.decnet.ab.com Stan Brown, Oak Road Systems, Cleveland, Ohio, USA +1 216 371 0043