I'm interested in using something other than the C preprocessor to preprocess my C and Objective-C source code. Are there good alternatives?
An example would be something that allowed one to escape out into a python or perl snippet in the middle of C code, and where the snippet spit out C that is then compiled as normal.
If you accidentally redefine a name with a #define , the compiler silently changes the meaning of your program. With const or enum you get an error message.
There are 4 Main Types of Preprocessor Directives:Macros. File Inclusion. Conditional Compilation. Other directives.
## is usued to concatenate two macros in c-preprocessor. So before compiling f(var,12) should replace by the preprocessor with var12 and hence you got the output.
The C preprocessor is a macro processor that is used automatically by the C compiler to transform your program before actual compilation. It is called a macro processor because it allows you to define macros, which are brief abbreviations for longer constructs.
You can use PHP as a C preprocessor. The advantages are:
<?
and ?>
are not used in standard C (with non-standard C, the only thing that gets broken is old GCC extension operator that returns min/max)For serious use though, making PHP print the #line directives is needed for debugging preprocessed code.
<?php include_once "stdio.h"; ?> int main() { <?php for($i = 0; $i < 20; $i++) echo 'printf("%d\n", '.$i.');'; ?> }
You might want to consider m4.
http://www.gnu.org/software/m4/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With