Turing Machine Implementation in C

China☆狼群 提交于 2019-12-04 13:52:34

The program provided is in C, however, you're compiling with a C++ compiler.

Compile again using C, and you should be ok.

The code is being treated as C++ because the file extension is .cpp. Change it to .c and it should work. This is much easier (and less likely to cause problems) then starting to modify the source code to make it C++ compatible.

Edit: I assumed the compiler being used was gcc or cl, which do detect the language based on the file extension. Since that is not the case, you'll have to tell us what compiler (and options) you are using.

Edit 2: In order to get it to work with a C++ compiler, you'll have to rename new to new1 like @whitelionV suggested and cast all the calloc() return values to the appropriate types like this:

44     Tape *new1 = (Tape*)calloc(1,sizeof(Tape));;
68     Tape *t = (Tape *)calloc(1,sizeof(Tape));
80     Transition *t = (Transition *)calloc(1,sizeof(Transition));
93     List *t = (List *)calloc(1,sizeof(List));
105    List *t = (List *)calloc(1,sizeof(List));
166    TM *m = (TM *)calloc(1,sizeof(TM));
167    List *tr = (List *)calloc(1,sizeof(List));

new is a reserved word in C++, change the variable name to something like new1. Or change the .cpp to c on your file name.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!