[2914] in java-interest

home help back first fref pref prev next nref lref last post

Re: Preprocessor features

daemon@ATHENA.MIT.EDU (patl@asimov.volant.org)
Fri Oct 20 13:53:58 1995

From: patl@asimov.volant.org
Date: Fri, 20 Oct 1995 08:40:19 -0700
To: java-interest@java.sun.com, mtravis@ncsa.uiuc.edu

|>  In actuality, you can use the C/C++ preprocessor to process *any* source 
|>  file before compilation, even Java source. The problem with this is that 
|>  you lose all pretty formatting and comments as part of the preprocessing. 
|>  If you preprocess as part of the compilation process, as is done in C and 
|>  C++, then this may not be a significant issue. I was porting some C code 
|>  that was so heavily-dependent on the preprocessor, that to remove the 
|>  #define's and such would have required basically a rewrite from scratch. 
|>  By maintaining the use of the preprocessor, I saved weeks of time. I was 
|>  using Borland's stand-alone preprocessor which comes with Borland C++.

There are a couple of other problems with using the C/C++ preprocessor
as a general-purpose macro processor:

1.  It has certain C/C++ semantics built in, with no way to turn them off.
    For example, if your text happens to contain '/*', the preprocessor
    starts eating text and looking for a '*/'.  Which is ok if your source
    happens to be sufficiently c-like to use that as comment notation...
    ANSI string concatenation, and ## processing can also cause problems.
    
2.  The built-in pre-defined macros can cause unexpected substitutions,
    and the specific words that cause problems will vary from system to
    system.  Of course, this can also be a problem in C/C++ programs
    themselves.  A few years ago a co-worker was having a hell of a time
    trying to figure out why he was getting a syntax error on a declaration.
    I had to point out that the preprocessor was replacing his variable name
    (unix) with a 1 because it happened to match one of the predefined macros
    for that system.
    
    
    
-Pat

My opinions are my own.  For a small royalty, they can be yours as well...
Pat Lashley, Senior Software Engineer, Henry Davis Consulting
patl@Phoenix.Volant.ORG  ||  http://Phoenix.Volant.ORG/  ||  lashley@netcom.com

-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post