Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Bartc <bc@freeuk.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Multi-line #defines |
| Date | 2015-09-18 14:32 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <mth3md$849$1@dont-email.me> (permalink) |
| References | <93f94067-33d7-42aa-a4dd-bde1e2fe9cd9@googlegroups.com> |
On 18/09/2015 01:50, Rick C. Hodgin wrote:
> Is there a C syntax, or variant of C syntax in use, which allows multi-
> line defines to be enclosed in standard braces, such that something
> like this...:
>
> #define abc line1\
> line2\
> line3
>
> ...is translated to be the same as something like this:
>
> #define abc {line1
> line2
> line3}
>
> And specifically I am considering something more human readable...:
>
> #define abc {
> line1
> line2
> line3
> } ignore_leading_whitespaces, ignore_leading_feeds, ignore_trailing_feeds;
Forget C or C variants (which you don't want to be tied down to anyway).
Invent a suitable new syntax, eg:
#mdefine name(args)
line1
line2
line3
#enddefine
This is then processed with the simplest of translation tools to result
in conventional C containing this:
#define name(args) \
line1\
line2\
line3\
// [blank line]
(The blank line helps preserve line numbers with the original, as well
as simplifying the logic by allowing \ on the last line.)
It's harder to end the block with "}", because that means having a
complete C syntax analyser within the translation tool.
(Here's some rather clunky pseudo-code to do such a translation on a
input file: http://pastebin.com/TMZa4UwR. No doubt it would be a
one-liner in a more apt scripting language, or in 'sed'. The point is,
it's simpler than changing the language and then changing every compiler
on the planet.)
> ...which in RDC syntax would be:
>
> #define abc
> | ignore_leading_whitespaces
> | ignore_leading_feeds
> | ignore_trailing_feeds
> {
> line1
> line2
> line3
> };
This won't work in general. Macro-bodies are not necessarily
well-formed, so you don't know if that final }, or }, is part of the
definition or not. Also, in C, it wouldn't be able to tell if this is
defining a blank macro called "abc", or a multi-line one.
This new language might have its own rules, but anyone looking at
'#define abc' by itself might well assume that it does what C does.
--
Bartc
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Multi-line #defines "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-09-17 17:50 -0700
Re: Multi-line #defines wssimms@gmail.com - 2015-09-17 21:13 -0700
Re: Multi-line #defines "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-09-17 23:20 -0700
Re: Multi-line #defines David Brown <david.brown@hesbynett.no> - 2015-09-18 14:13 +0200
Re: Multi-line #defines "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-09-18 05:28 -0700
Re: Multi-line #defines mark.bluemel@gmail.com - 2015-09-18 05:43 -0700
Re: Multi-line #defines "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-09-18 05:46 -0700
Re: Multi-line #defines Keith Thompson <kst-u@mib.org> - 2015-09-18 08:39 -0700
Re: Multi-line #defines Tim Rentsch <txr@alumni.caltech.edu> - 2015-09-26 17:42 -0700
Re: Multi-line #defines Philip Lantz <prl@canterey.us> - 2015-09-19 00:32 -0700
Re: Multi-line #defines "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-09-19 11:54 -0700
Re: Multi-line #defines Philip Lantz <prl@canterey.us> - 2015-09-19 12:50 -0700
Re: Multi-line #defines "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-09-19 12:58 -0700
Re: Multi-line #defines gazelle@shell.xmission.com (Kenny McCormack) - 2015-09-19 09:16 +0000
Re: Multi-line #defines Richard Damon <Richard@Damon-Family.org> - 2015-09-18 08:38 -0400
Re: Multi-line #defines "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-09-18 05:45 -0700
Re: Multi-line #defines gazelle@shell.xmission.com (Kenny McCormack) - 2015-09-18 10:43 +0000
Re: Multi-line #defines Bartc <bc@freeuk.com> - 2015-09-18 14:32 +0100
Re: Multi-line #defines "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-09-18 06:43 -0700
Re: Multi-line #defines wssimms@gmail.com - 2015-09-18 09:31 -0700
Re: Multi-line #defines supercat@casperkitty.com - 2015-09-18 10:24 -0700
Re: Multi-line #defines Siri Cruz <chine.bleu@yahoo.com> - 2015-09-18 10:12 -0700
Re: Multi-line #defines gordonb.vjjox@burditt.org (Gordon Burditt) - 2015-09-18 17:54 -0500
Re: Multi-line #defines "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-09-18 16:30 -0700
Re: Multi-line #defines gazelle@shell.xmission.com (Kenny McCormack) - 2015-09-19 09:22 +0000
Re: Multi-line #defines Bartc <bc@freeuk.com> - 2015-09-19 11:31 +0100
Re: Multi-line #defines Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-09-19 13:26 +0100
Re: Multi-line #defines Bartc <bc@freeuk.com> - 2015-09-19 14:11 +0100
Re: Multi-line #defines Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-09-19 07:01 -0700
Re: Multi-line #defines Les Cargill <lcargill99@comcast.com> - 2015-09-19 11:23 -0500
Re: Multi-line #defines "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-26 20:05 -0700
Re: Multi-line #defines Ian Collins <ian-news@hotmail.com> - 2015-10-27 16:08 +1300
Re: Multi-line #defines "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-26 20:16 -0700
Re: Multi-line #defines supercat@casperkitty.com - 2015-10-27 06:30 -0700
Re: Multi-line #defines "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-27 06:52 -0700
csiph-web