我讀到Objective-C是通過使用預處理器指令將Smalltalk的功能添加到C,這讓我有點好奇,因此我開始修改C++中的預處理器,僅僅因爲我是無聊與此想出了:使用預處理器來更改語言語法
#include <iostream>
#include <string>
#define Constant const
#define Integer int
#define Real double
#define Boolean bool
#define Character char
#define String string;
#define System system
#define StandardLibrary std
#define OutputStream cout
int main()
{
Integer i = 1;
Integer ii = 2;
Integer iii = ii + i;
StandardLibrary::OutputStream<<iii;
System("pause");
return 0;
}
所以,是的,這是很明顯,你可以更改使用預處理器的名稱,但它是如何可以實現一種語言的功能集成到使用預處理器的另一種語言?
我不打算通過這個使我自己的語言。我只是好奇,看看它是如何工作的。
有什麼問題嗎? –
你做了什麼改進,甚至有幫助?順便說一句,你可以使用'typedef'或'using'來完成你所做的大部分事情。 –
不是!我只想知道如何使用預處理器將一種語言的特性實現到另一種語言中。 –