SDCC does currently not support K & R style functions, even though support is required by the C standard.
Philipp
Patches: #287
Wiki: SDCC 4.3.0 Release
Wiki: SDCC 4.4.0 Release
Wiki: SDCC 4.5.0 Release
Wiki: SDCC 4.6.0 Release
Wiki: SDCC-STD-UX
My understanding is that K&R style functions
have been deprecated since ANSI C (1989); which recommended ANSI C style functions
Is there any real code likely to be compiled by SDCC that uses even one K&R style function?
So far, the only program I came across that I wanted to compile with SDCC that uses K&R-style functions was Dhrystone. But that one seems important enough to make me want support for it in SDCC.
So far I'm using a version where I changed the funcion style to be abe to compile it with SDCC. But benchmark programs only have a few places that are supposed to be changed to make them work on compiler/hardware combinations, and in Dhrystone, the function style is not one of them. So I feel a bit uncomfortable using the modified benchmark.
Philipp
I agree that it would be really nice if SDCC could run benchmarks without any modification.
On the other hand, I don't see any reason for SDCC to ever support the original version of Dhrystone (written in Ada).
Rather than change SDCC to support a language dialect that almost no one still uses, or modify the Dhrystone source code yourself to get it to compile with SDCC (and risking introducing unfair bias), you might consider other options, such as:
(a) Use a translated ANSI C version of Dhrystone written by someone else long ago, similar to the way the K&R C version of Dhrystone is itself a translated version of the original Ada version of Dhrystone.
I see one ANSI C version apparently written in 2004 available for download at http://www.ecrostech.com/Other/Resources/Dhrystone.htm .
(b) Perhaps some other benchmark work work just as well -- perhaps even better than Dhrystone.
There's a long list of benchmarks at
https://en.wikipedia.org/wiki/Benchmark_(computing)
although unfortunately most of them require more memory than is available on most of the systems SDCC supports.
I hear good things about the HINT benchmark ( https://en.wikipedia.org/wiki/Hierarchical_INTegration ) -- would that work for you?
The latest official version of Dhrystone is 2.1, which comes both in an Ada and a C version.
I have been looking for suitable benchmarks for the systems SDCC targets for some time, and so far found only Dhrystone, Whetstone and Coremark. They seem rather orthogona to me, so for a good test, I need all three of them.
K&R-style functions are still part of the C standards (C90, C99, C11), so we need them for full standard compliance.
Since SDCC targets some older architectures found in older systems, it is not that uncommon for people to wat to compile older programs. Just two days ago I noticed a post about some chess program on the z88dk list that someone finally got to compile with SDCC, and one of the issues they encountered were the K&R-style functions.
Philipp
Personally I hate K&R-style functions. They go against everything I call good practice. Therefore I would want SDCC to warn against their use if they get supported.
A warning seems appropriate (both here and for any other obsolescent features).
Philipp
Yet another workaround option:
(c) Use an automated tool to mechanically create a directory full of ANSI C source code from a directory full of K&R source code, similar to the way some people use an automated tool to mechanically convert a directory full of ANSI C source code from a directory full of Fortran code.
K&R C to ANSI C: "Converting K&R to ANSI C" http://www.sunmanagers.org/archives/1992/0833.html
mentions many tools, including
protoize https://gcc.gnu.org/onlinedocs/gcc-3.4.2/gcc/Running-Protoize.html
cproto http://invisible-island.net/cproto/cproto.html
extproto with the --toANSI switch http://alumnus.caltech.edu/~sedwards/ext/
ansification ( http://invisible-island.net/ansification/#what_tools ) has some discussion on converting K&R C to ANSI C.
Fortran to C: https://en.wikipedia.org/wiki/F2c http://cci.lbl.gov/fable/ http://simulationcorner.net/index.php?page=if2c etc.
If none of those tools actually work, perhaps we could build one.
comp.lang.c FAQ:
"Q: Does anyone have a tool for converting old-style C programs to ANSI C...?"
-- http://c-faq.com/ansi/cproto.html
See [patches:#287] for a patch that adds partial support.
Related
Patches:
#287Syntactic support is in [r15071].
Semantically, they are currently treated like ISO-style functions, because support for prototype-less functions with arguments is not quite there, yet.
Related
Commit: [r15071]