Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compile C code using old syntax with a modern compiler?

Tags:

c

llvm

I'm on OS X using i686-apple-darwin11-llvm-gcc-4.2, and I'm trying to compile various programs from this archive, and in particular the classical FitCurves.c which fits a Bezier curve through an array of points.

http://tog.acm.org/resources/GraphicsGems/

Some void or int functions are defined without a return type, which generates warning.

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;}

I'm not really sure about this: there is an error

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) */

As I understand it, it seems that the compiler thinks it's implicitely declared as a function returning an int, but the function returns void, causing an error. Does it make sense in C to return from a function that is declared to return an int ? I'm confused here..

How may I compile this nicely ? I doesn't necessarily fail to compile but the warnings are not very informative. It's written using an old syntax, and I know it.

like image 482
alecail Avatar asked Feb 17 '23 06:02

alecail


1 Answers

You can just disable that warning since you don't care about it:

-Wno-implicit-int

Also, are you sure you're using llvm-gcc? When I made a test with your example, I had to add -Wall to get gcc to say:

$ gcc -Wall -c -o example.o example.c
example.c:8: warning: return type defaults to ‘int’

But clang said:

$ clang -c -o example.o example.c
example.c:8: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;}
^~~~~~~~~~~
1 warning generated.

without any flags at all, and that message more closely matches the warning in your question. On my machine:

$ 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
like image 157
Carl Norum Avatar answered Mar 04 '23 01:03

Carl Norum