Unravel the Mystery Code

Difficulty: Easy

The C compiler preprocessor is a sneaky and powerful thing. I’m unsure of any other programming languages that have such a tool.

For example, you can redefine pretty much the entire language, not only keywords but operators and elements of syntax. To wit, this code compiles and runs:

begin program
start
print("Hello!")
end
stop

This code outputs the text Hello!. It compiles using any C compiler. It works. Of course, this example isn’t the entire code. That’s because a series of #define preprocessor directives creates the faux code. When the preprocessor is done, the compiler recognizes everything and creates a program.

Your task for this month’s Exercise is to write the complete C program. It contains the lines listed above, which are the final lines of code. But your solution also features a series of preprocessor directives that make everything work. You must properly code those directives.

Click here to view my solution.

Leave a Reply