Hacker News new | ask | show | jobs
by anonymousiam 904 days ago
I grabbed this when it was originally published, but somehow the file name I have is different from the one in this article. Mine is called "carol.c" and I just compiled and ran it on a modern system. The compiler spat out the following warnings:

gcc -o carol carol.c

carol.c:2:1: warning: return type defaults to ‘int’ [-Wimplicit-int]

    2 | main(t,_,a )

      | ^~~~
carol.c: In function ‘main’:

carol.c:2:1: warning: type of ‘t’ defaults to ‘int’ [-Wimplicit-int]

carol.c:2:1: warning: type of ‘_’ defaults to ‘int’ [-Wimplicit-int]

3 comments

GCC 14 won't permit implicit int any more ... https://fedoraproject.org/wiki/Changes/PortingToModernC#Remo...
I guess I got lucky then. This Ubuntu 23.10 install has gcc 13.2.0-4ubuntu3 installed from the repo. Given that the code is pre-ANSI C, and that it won in the category of "Least likely to compile successfully", it's surprising that there are no other issues.

I wouldn't normally run such a radioactive distro, but this laptop is so new that there is no LTS distro that works on it. (AMD Ryzen 7 PRO 7840U w/ Radeon 780M Graphics)

Just compile with -std=c89
Good. It's almost as bad as not returning a value from a function being a warning and not an error.
The issue is calling xmas() in main before it's defined. Compiling with GCC on macOS gives the error:

  xmas.c:16:5: error: call to undeclared function 'xmas'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
    xmas(2, 2, "");
Moving main() to the bottom compiles and executes with the proper output.
Real GCC or Apple’s clang symlinked to gcc?
Surprisingly few warnings, and all on the same line!