This is very interesting.

> This is what happens in the sources of clisp, written in .d files, which
> are pre-processed to produce the actual .c intermediary files.

It makes so much sense now, why all the code was written in pre-processed files. Although I did know
there was supposed to be lot of compile time and template changes made due to multiple platforms
and additional flags and options.

Thanks! Exchanging emails with all you amazing people provides so much learning.

---
P.S. -
I hate to disappear. But I spent the past 2-3 days without internet connection since it broke due to some construction near my house.
Anyway back to normal. Good to be online now.




On Sun, May 4, 2014 at 10:56 PM, Pascal J. Bourguignon <pjb@informatimago.com> wrote:


On 04 May 2014, at 19:05, shashank <shashankgrovy@gmail.com> wrote:

> Hey
>
> Oh! so that's how its used.
> Very nicely explained :)
>
> Actually I have never seen so many C macros at once and it gets quite overwhelming. In the past I have mostly used C for coding algorithms and small stuff, for everything else I used python.
> But this is lovely.

Notice that you can use the C processor on any kind of text, including any kind of programming language.

Two examples:

In standard Pascal (as defined in the 70s), a program was made of a single file, there were no units or libraries.
However, you could use #include (and #define, #if, etc if needed), to build this single file program using cpp.

Another example, that I have used recently, for a specification document where two different objects are specified
to have similar fields, with only small variants.  The specification for the fieds are given in the file rule-actions.txt,
which contains a few text section in #ifdef / #else / #endif, and a Makefile contains rules to generate the two variants:


rule-actions-beacon.txt:rule-actions.txt  Makefile
        @echo "Preprocessing $< for beacons"
        @cpp -CC -P  -traditional-cpp \
            -DBEACON \
            -o rule-actions-beacon.txt rule-actions.txt

rule-actions-geofence.txt:rule-actions.txt  Makefile
        @echo "Preprocessing $< for geofences"
        @cpp -CC -P  -traditional-cpp \
            -UBEACON \
            -o rule-actions-geofence.txt rule-actions.txt


That said, while cpp is almost Turing Complete (if you use it it a loop, it becomes Turing Complete), it is still
quite very rudimentary, and often you will want to write your own specific pre-processor.  This is what happens
in the sources of clisp, written in .d files, which are pre-processed to produce the actual .c intermediary files.

This is a very common technique.  A lot of languages began life as C pre-processors (Objective-C, C++ (cfront), Pro*C, etc).


__Pascal Bourguignon__