问题
I am reading the book "C++ Primer" 5th Edition and I read that the preprocessor is a program that runs before the C++ compiler and replaces the #include, #define and #ifdefs and others with the appropriate content and then transfer control over to the compiler.
But I came across a way in cl.exe (Microsoft Compiler) to view the preprocessor output saved directly to file. I did it, and when I opened the preprocessor output file I was surprised because I did not find what I expected!
They were totally big and contained what looked like obfuscated code!
Please Explain what in reality does the Pre-Processor of C++ does.
回答1:
It is entirely possible to pre-process Java just like you do C or C++. Just use something like this:
gcc -E myjava.java > myjava.preprocesses.java
Then you can use macro expansion, #if
etc to your hearts content. Of course, it does have the drawback that there is a further tool needed for the compile.
回答2:
You can roll out a JNI lib that ties in with your native C/C++ code that has all your necessary macros.
来源:https://stackoverflow.com/questions/16253977/how-does-c-preprocessor-work