C&C++   发布时间:2022-04-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了如何使用旧语法和现代编译器编译C代码?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我在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

大佬总结

以上是大佬教程为你收集整理的如何使用旧语法和现代编译器编译C代码?全部内容,希望文章能够帮你解决如何使用旧语法和现代编译器编译C代码?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。