C/C++ Professor: See how your compilation happens
Consider the coloured program code above. It is a fairly complicated piece of code largely taken from page 156 of the C99 ANSI/ISO standard. Try translating the program to see if you can understand it, like a compiler does. If you find the going tough, then allow our Macro Magic V1.1 expert system called Professor to explain this to you.
Macro Magic® is the world's only educational C/C++ preprocessor. Furthermore, it is the world's only standalone, C/C++ preprocessor with this and other attributes. This expert system explains C/C++ compilation up to phase 7.1 of standard compilation, which is how far Macro Magic presently compiles. Of the total 8 phases that C/C++ compilation is comprised of, this is a fairly large subset. This includes all of preprocessing, including a detailed tracing of individual macros, and tracing of the control expression of conditional compilation. The colouring scheme put out by Professor, in the code above, is the compilation explanation. Pink colour comprises code that is deleted in the preprocessing steps. The chopping up of non-deleted text into pre-processor-tokens (like lexemes) is shown by the alternation of colours (e.g. black and white). String concatenation is shown as strings of either all red or all blue colour, when separated by at most pink/deleted text. Comments, join, and trigraphs are very clearly highlighted, as they all make up deleted or replaced entities. Macro processing and conditional compilation can be very involved. Here macro processing is shown for the evaluation of m(m), which is underlined since it is a hyperlink. Hovering on the hyperlink shows the summary of macro expansion, comprising m! m? w as shown. m! means the first call to m results in a recursive call to m, which surprisingly it does, despite the #define not containing any explicit recursion. The m? means a second, questionable call to m is encountered in processing the first call, which turns out to be improper and hence is prematurely terminated. This if you note carefully, happens when the argument m of the outer m call is macro expanded. Finally, w implies that this macro is also expanded in the outer m call, without any notable consequences. If this summary intrigues a user of Professor, then she can click on the hyperlink, which then yields the detailed explanation for the call i.e. the summary's full explanation. The other macro calls in the example above are also highly challenging. Having Macro Magic on your side, makes understanding them a piece of cake.
The Professor system comprising five plug-ins (forthcoming) has three exemplar plug-ins whose core is contributed by our honorary interns, Jyoti, Jayant and Jeevan Varma, illustrating the ease with which even difficult programs can be made pluggable for universal use, i.e. both serial and parallel contexts. The exemplar codes will shortly be made available on this page, once testing is complete.
BNS® Macro Magic: Buff your knowledge with us!
Clicking the hover link m(m) yields:
In the following, $ marks an end of a (nested) macro explanation.
/*/ /*
Macro expands as:
Beginning macro instantiation number 1
m(m) =>
Macros in arguments may be expanded first as follows:
Beginning macro instantiation number 2
m =>
Abandoned expansion of instantion number: 2, because the left parenthesis of the macro function call is missing.
$
Macro arguments processing done for instantiation number 1
m(m) => m(w)
Revisit for macro instantiation number 1 causes the following macro expansions :
Beginning macro instantiation number 3
m =>
Abandoned expansion of instantion number: 3, because of recursion. Hereafter, this token is marked recursive.
$
Beginning macro instantiation number 4
w => 0,1
Revisit for macro instantiation number 4 causes the following macro expansions :
Finished Revisit for instantiation number 4. No macro expansions were carried out.
=> 0,1
$
Finished Revisit 1
=> m(0,1)
$
*/