Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!gatech!bloom-beacon!eru!hagbard!sunic!ugle.unit.no!sigyn.idt.unit.no!sigyn.idt.unit.no!bjornmu From: bjornmu@idt.unit.no (Bj|rn P. Munch) Newsgroups: comp.lang.c Subject: Re: Macros with multi-line results? Message-ID: <1991Jan11.022715.21451@idt.unit.no> Date: 11 Jan 91 02:27:15 GMT References: <16101@burdvax.PRC.Unisys.COM> Sender: news@idt.unit.no (Usenet news admin) Organization: Div. of CS & Telematics, Norwegian Institute of Technology Lines: 54 In article <16101@burdvax.PRC.Unisys.COM>, fritzson@PRC.Unisys.COM (Richard Fritzson) writes: |> I am trying to write a macro which generates more than one line of |> output. Defining a macro such as |> |> #define foo(a,b) body \ |> more body \ |> still more |> |> and invoking it with |> |> foo (one, two) |> |> produces: |> |> body more body still more |> |> as output from the C preprocessor. I would very much like to get |> |> body |> more body |> still more |> |> somehow. Is this possible? Yes, with a little help from tr. I had to do the same thing once, and my solution was to write the macro like this: #define foo(a,b) body @\ more body @\ still more , and then process it like this: (foo.xc is the source with the macro) cpp -P foo.xc | tr '@' '\012' > foo.c Then you can compile foo.c. In my case, I had a 100 line macro expanding to function bodies with statements in embedded SQL. I had to do this trick because the SQL statements had to be at the start of a line for the preprocessor. Even worse, I needed to use macro arguments that contained commas, but that problem could be solved in the same way..... :-) Your cpp may choke on the @ sign, in which case you can try a "legal" C character like ?, | or ~. Just make sure you don't need that character for its "real" purpose anywhere else in the file. Good luck! ----- Bj|rn P. Munch | Div. of Comp. Science & Telematics, bjornmu@idt.unit.no | Norwegian Institute of Technology (NTH), PhD Student | Trondheim, Norway (some filler words here) | You can finger me @jod.idt.unit.no