Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.std.c++ > #621

Re: A preprocessor feature we should have had 40 years ago

From jacob navia <jacob@spamsink.net>
Newsgroups comp.std.c++
Subject Re: A preprocessor feature we should have had 40 years ago
Date 2013-05-25 02:23 -0700
Organization lccwin
Message-ID <knn1hf$143$1@speranza.aioe.org> (permalink)
References <UrKdnTRjb8pONQDMnZ2dnUVZ_oudnZ2d@earthlink.com>

Show all headers | View raw


Le 24/05/13 03:18, Paul D. DeRocco a écrit :
> the contents of the block would
> be repeated that number of times, with the preprocessor identifier
> taking values 0 through n-1. Even with a fixed count, this can be useful:
>
>      const int squares[] = {
>      #repeat I 101
>          I * I,
>      #endrepeat
>      };

I am thinking about a C program that:

1) opens a text file. Output is ON: lines are copied to a temporary file.

2) Scans all lines selecting those that start with the character string
"#repeat" followed by  space/tab. All lines are copied to the temporary
file.

3) When a repeat directive is detected, it reads an identifier and the
count. Output is OFF, i.e. lines are read without being copied into the
temporary file but appended to a temporary buffer.

4) Goes on scanning lines in replace mode, replacing all identifiers
that match the given one by a placeholder.

5) When it reaches the end repeat directive (that is searched for only
in replace mode) builds a loop of N iterations outputting the text found
within the directive. The place-holders are replaced by the textual form
of the integer counter.

5) Output is set to ON again and processing continues at step 2.

6) End of file is seen. Processing stops, file is closed and the
compiler is called to process the temporary file. This shouldn't happen
in replace mode.

Of course this is bare bones. More expensive versions accept an
increment count (that defaults to 1), a printf format string for the
counter (that defaults to "%d") and probably other stuff that will be
discovered with usage: parameters to the expansion (should spaces be
added between the replacement text or not? should new lines be honored
in the output or should the output be a single line? etc) or even other
useful directives not discovered yet.


This makes for a very simple C program, at most 500 or 1000 lines...

Remember RATFOR?

RATC exists, you have just proposed it (again).

jacob



-- 
[ comp.std.c++ is moderated.  To submit articles, try posting with your ]
[ newsreader.  If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]

Back to comp.std.c++ | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

A preprocessor feature we should have had 40 years ago "Paul D. DeRocco" <pderocco@ix.netcom.com> - 2013-05-23 19:18 -0600
  Re: A preprocessor feature we should have had 40 years ago Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-05-24 15:19 -0700
  Re: A preprocessor feature we should have had 40 years ago jacob navia <jacob@spamsink.net> - 2013-05-25 02:23 -0700
  Re: A preprocessor feature we should have had 40 years ago Keith Thompson <kst-u@mib.org> - 2013-05-25 02:24 -0700
    Re: A preprocessor feature we should have had 40 years ago "Kenneth \"Bessarion\" Boyd" <zaimoni@zaimoni.com> - 2013-05-25 23:43 -0700
    Re: A preprocessor feature we should have had 40 years ago "Paul D. DeRocco" <pderocco@ix.netcom.com> - 2013-05-25 23:44 -0700
      Re: A preprocessor feature we should have had 40 years ago Francis Glassborow <francis.glassborow@btinternet.com> - 2013-05-26 08:52 -0600
  Re: A preprocessor feature we should have had 40 years ago Rui Maciel <rui.maciel@googlemail.com> - 2013-05-25 23:43 -0700
  Re: A preprocessor feature we should have had 40 years ago Peter <pcurran88@googlemail.com> - 2013-05-30 19:40 -0600
    Re: A preprocessor feature we should have had 40 years ago "Paul D. DeRocco" <pderocco@ix.netcom.com> - 2013-06-01 02:04 -0600
      Re: A preprocessor feature we should have had 40 years ago ootiib@hot.ee - 2013-06-01 14:53 -0600
      Re: A preprocessor feature we should have had 40 years ago James Kuyper <jameskuyper@verizon.net> - 2013-06-04 10:41 -0600
        Re: A preprocessor feature we should have had 40 years ago espie@lain.home (Marc Espie) - 2013-06-05 23:12 -0700
          Re: A preprocessor feature we should have had 40 years ago James Kuyper <jameskuyper@verizon.net> - 2013-06-06 09:20 -0700
  Re: A preprocessor feature we should have had 40 years ago Jens Schweikhardt <usenet@schweikhardt.net> - 2013-06-09 02:21 -0700

csiph-web