Yesterday I found a tiny C compiler (less than 600 line of C code, containing commits) called "c4" on github and I wanted to know how I can write a compiler in details.
During the process, I encounter the following problems:
1> Can not compile c4 on Windows platform, because no "unistd.h" on Windows.
solution: replace the include sentence by the following statements:
所以用VC编译总是报错。把下面的内容保存为unistd.h,可以解决这个问题。
- /** This file is part of the Mingw32 package.
- * unistd.h maps (roughly) to io.h
- */
- #ifndef _UNISTD_H
- #define _UNISTD_H
- #include <io.h>
- #include <process.h>
- #endif /* _UNISTD_H */
2> IDEs:
First tried Vitual Studio 2013, it was hard for me to get used the VS after some many years' leave. I could not find the proper functions to satisfy my needs.
Eclipse: Downloaded the Eclipse-CDT(for C/C++ development). Dowload the minGW project, containing the gcc and other lib file for windows. Configure eclipse, it is not complicated after I configure the BarLearner project from Cristian. Just make the build system right, and adjust the run configuration. But I fould I could not the value of global values and for most pointers, I could only see the address its point to rather than the content (for example, I wanted to see an array, but got nothing useful for me.) Searching on the Internet, someone said we can see the global values on "Watch" windows. However, I did not think so after trying. I gave it up temporary.
VC6.0: This is a very old platform I had been working on for years. It took me time to install VC 6.0 on Windows 8.1. Here are some useful solution for the installation:
2 兼容模式修改成 winxp sp2 或者sp3
3 启动MSDEV3.EXE,如果报错,关闭,立刻再次启动,一般就可以正常启动了,成功启动一次后,以后就可以正常运行了
4 取消兼容模式,如果运气好,也可以正常运行了,如果不介意,就一直用兼容模式运行也可以"