如何使用旧语法和现代编译器编译C代码?
发布时间:2020-12-16 09:45:31 所属栏目:百科 来源:网络整理
导读:我在OS X上使用i686-apple-darwin11-llvm- gcc-4.2,我正在尝试从 this archive编译各种程序,特别是经典的FitCurves.c,它通过一系列点拟合贝塞尔曲线. http://tog.acm.org/resources/GraphicsGems/ 某些void或int函数是在没有返回类型的情况下定义的,这会生成
我在OS X上使用i686-apple-darwin11-llvm-
gcc-4.2,我正在尝试从
this archive编译各种程序,特别是经典的FitCurves.c,它通过一系列点拟合贝塞尔曲线.
http://tog.acm.org/resources/GraphicsGems/ 某些void或int函数是在没有返回类型的情况下定义的,这会生成警告. ConcaveScan.c:149:1: warning: type specifier missing,defaults to 'int' [-Wimplicit-int] compare_ind(u,v) int *u,*v; {return pt[*u].y <= pt[*v].y ? -1 : 1;} 我不太确定这个:有一个错误 cc -g -Wno-implicit-int -Wreturn-type -c -o AAPolyScan.o AAPolyScan.c AAPolyScan.c:106:4: error: non-void function 'drawPolygon' should return a value [-Wreturn-type] return; /* (null polygon) */ 据我了解,似乎编译器认为它被隐含地声明为返回int的函数,但该函数返回void,导致错误.在C中从声明返回int的函数返回是否有意义?我在这里很困惑.. 怎么可以很好地编译呢?我不一定无法编译,但警告不是很有用.它是用旧语法编写的,我知道. 解决方法
您可以禁用该警告,因为您不关心它:
-Wno-implicit-int 另外,你确定你正在使用llvm-gcc吗?当我用你的例子进行测试时,我不得不添加-Wall来让gcc说: $gcc -Wall -c -o example.o example.c example.c:8: warning: return type defaults to ‘int’ 但克朗说: $clang -c -o example.o example.c example.c:8:1: warning: type specifier missing,defaults to 'int' [-Wimplicit-int] compare_ind(u,*v; {return pt[*u].y <= pt[*v].y ? -1 : 1;} ^~~~~~~~~~~ 1 warning generated. 没有任何标志,并且该消息更符合您问题中的警告.在我的机器上: $gcc --version i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00) Copyright (C) 2007 Free Software Foundation,Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $cc --version Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn) Target: x86_64-apple-darwin12.4.0 Thread model: posix (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |