Using the c preprocessor for non c purposes 
Author Message
 Using the c preprocessor for non c purposes

While just toying around, I was wondering if I can use the c preprocessor
for just about anything.

----C related-----
say i have a text file, called 'letter', which contains a directive #include
"address".   (address being
another text file).

gcc's -E let's me just run files through the C preprocessor.  How can I, if
possible, retrieve the output of the preprocessed file?

----Perl related----
I know that perl can run source code through the C preprocessor before
interpreting.  (-P option).  However, when running ActivePerl on Win32 it
complained that it could not find 'sed'!!!!  After installing a win32 'sed'
it complained that there is no 'cl'.

Using a homebuilt Perl on Linux, the -P option worked as expected.

B.



Tue, 02 Mar 2004 09:37:25 GMT  
 Using the c preprocessor for non c purposes


Quote:
> While just toying around, I was wondering if I can use the c
preprocessor
> for just about anything.

> ----C related-----
> say i have a text file, called 'letter', which contains a directive
#include
> "address".   (address being
> another text file).

> gcc's -E let's me just run files through the C preprocessor.  How can
I, if
> possible, retrieve the output of the preprocessed file?

cpp <thefile >prepfile
gives you the output in the 'prepfile' file. (the < and > must appear
litterally)


Tue, 02 Mar 2004 10:30:00 GMT  
 Using the c preprocessor for non c purposes
Hi,

Quote:
> While just toying around, I was wondering if I can use the c preprocessor
> for just about anything.

Yes you can, it works fine. A Unix tool called m4 is the traditional
generic preprocessor, but its use seems rare. For a while I used the C
preprocessor to build my website. I ended up writing a C pre-processor
clone in Perl, which ommitted some of the features relevant to C and
added features I wanted for my website (automatic navigation bars,
graphical titles, etc.)

A word of warning though, other people may find your source code hard to
understand if you make heavy use of preprocessing, especially if using a
language where this is not normally done (e.g. batch files).

Paul



Tue, 02 Mar 2004 15:46:36 GMT  
 Using the c preprocessor for non c purposes
: Hi,

: > While just toying around, I was wondering if I can use the c preprocessor
: > for just about anything.

Though on windows the tools required are usually missing.  The Perl angle
is that a perl script that uses the proprocess option won't run on a
typical windows machine even when it has an otherwise complete and working
perl installed.



Tue, 02 Mar 2004 18:48:27 GMT  
 Using the c preprocessor for non c purposes

Quote:

> While just toying around, I was wondering if I can use the c preprocessor
> for just about anything.

There's no requirement that the preprocessor be a separate program.
As you've seen, it is separate in gcc; it may not be in other
implementations.

One thing to watch out for is that the preprocessor parses its input
into a sequence of valid preprocessor tokens.  This may be a problem
for some input text.  For example, an input line with an odd number of
apostrophes or double quotes is likely to cause an error.  (This has
caused problems for attempts to use the C preprocessor on Ada source
code.  Ada uses a single apostrophe to introduce an attribute name, as
in Object'Size.)

--

San Diego Supercomputer Center           <*>  <http://www.sdsc.edu/~kst>
Cxiuj via bazo apartenas ni.



Wed, 03 Mar 2004 00:37:26 GMT  
 Using the c preprocessor for non c purposes
On Fri, 14 Sep 2001 10:37:25 +0200, "B. Caligari"

Quote:

> gcc's -E let's me just run files through the C preprocessor.  How can I,
> if possible, retrieve the output of the preprocessed file?

Open a pipe to the preprocessor and read in the output from there? (e.g.
with popen())

Quote:
> ----Perl related----
> I know that perl can run source code through the C preprocessor before
> interpreting.  (-P option).  However, when running ActivePerl on Win32 it
> complained that it could not find 'sed'!!!!  After installing a win32 'sed'
> it complained that there is no 'cl'.

'cl' is the name of Microsoft's compiler and linker driver, e.g. for MS
Visual C++. Windows doesn't come with a C preprocessor, or a compiler
for that matter, so I presume your Perl expects the C preprocessor with
which it was built to be present on your system.

Have you got Microsoft Visual C++ installed? If so, did you run
vcvars32.bat before trying -P? If not, which C preprocessor did you
expect Perl to use?

Cheers,
Philip
--

That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.



Wed, 03 Mar 2004 15:53:25 GMT  
 Using the c preprocessor for non c purposes
#if IMPLEMENTATION_SPECIFIC_ON_CLC

Quote:
> While just toying around, I was wondering if I can use the c preprocessor
> for just about anything.

For a lot of things that use lexemes compatible with C rules, yes.
People have even gotten it to work on "good" fortran, although
IMNSHO it's quicker to just bash yourself in the head with a brick.

...

Quote:
> gcc's -E let's me just run files through the C preprocessor.  How can I, if
> possible, retrieve the output of the preprocessed file?

Redirect stdout (on systems that support it) or use -o.
info gcc / Options Controlling Kind of Output

You may also want -P, and possibly -C if you use C comment syntax.
info gcc / Options Controlling the Preprocessor

--
- David.Thompson 1 now at worldnet.att.net



Sun, 07 Mar 2004 06:32:27 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Using the preprocessor

2. Using non-blocking sockets on Win2000

3. DBI and mysql using non-default socket question

4. non-blocking fh reads using select

5. Using perl to ftp non interactively

6. Reading non-ASCII from XML file using DOM module

7. newbie - grep non-used uid from passwd

8. Using mainloop for non-GUI jobs

9. The purpose of Symbol::delete_package()

10. PQ Edit general purpose database editor application and RDBAL module

11. What is the best way to...[general purpose perl timing utility]

12. Purpose of Exporter package ?

 

 
Powered by phpBB® Forum Software