Menu

#450 K & R function style

None
open
None
5
2024-11-03
2015-08-02
No

SDCC does currently not support K & R style functions, even though support is required by the C standard.

Philipp

Related

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

Discussion

  • David Cary

    David Cary - 2015-08-15

    My understanding is that K&R style functions

    bar(a,b,c){ return a/(b+c); }
    

    have been deprecated since ANSI C (1989); which recommended ANSI C style functions

    int bar( int a, int b, int c ){ return a/(b+c); }
    

    Is there any real code likely to be compiled by SDCC that uses even one K&R style function?

     
  • Philipp Klaus Krause

    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

     
  • David Cary

    David Cary - 2015-08-16

    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?

     
  • Philipp Klaus Krause

    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

     
  • Maarten Brock

    Maarten Brock - 2015-08-16

    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.

     
    • Philipp Klaus Krause

      A warning seems appropriate (both here and for any other obsolescent features).

      Philipp

       
  • David Cary

    David Cary - 2015-10-06

    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

     
  • Benedikt Freisen

    See [patches:#287] for a patch that adds partial support.

     

    Related

    Patches: #287

  • Benedikt Freisen

    • assigned_to: Benedikt Freisen
    • Group: -->
     
  • Benedikt Freisen

    Syntactic 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]


Log in to post a comment.

MongoDB Logo MongoDB