Menu

#3226 too many parameters error

open
nobody
None
Front-end
5
2023-02-01
2021-05-06
No

An example code:

void f(){}
void main() { f(0); }

In C a function declared as func() should be treated as having an unspecified number of untyped parameters, but SDCC compiler reports error 101: too many parameters.

Discussion

  • Philipp Klaus Krause

    • Category: STM8 --> Front-end
     
  • Rajmund Szymański

    Below an example of a code that should compile without errors.

    typedef void func();
    
    void f(int i) { (void) i; }
    
    void main()
    {
        func *g = (func *)f;
        g(0);
    }
    
     

    Last edit: Rajmund Szymański 2021-05-06
  • Philipp Klaus Krause

    I just checked, and at least your first example is indeed still valid C. An empty parameter list is still allowed in the latest C23 draft, despite already being listed as obsolescent in the very first C standard (ISO C90, section 6.9.4).

    SDCC should compile the code, but emit a warning (the non-normative Annex I of the C standard recommends a warning).

    Also, I should submit a proposal to WG14 to remove this from C23.

     

    Last edit: Philipp Klaus Krause 2021-05-06
  • Rajmund Szymański

    In example below:

    typedef void func();
    void f(int i) { (void) i; }
    func *g = f;
    

    compiler reports error 78: incompatible types.

     
  • Maarten Brock

    Maarten Brock - 2021-05-13

    Rajmund,

    Are you being pedantic that you want this supported just because the standard allows it? Or do you really want to use it? And if so, why o why? This violates good design patterns!

    SDCC should never support this IMHO. I vote to reject this bug.
    Maarten

     
    • Philipp Klaus Krause

      Its in the current C standard, so SDCC should support it. Not being standard-compliant is a bug.

       
  • Rajmund Szymański

    No problem. I'm using this feature in my RTOS project. SDCC was one of the supported compilers.

     
  • Philipp Klaus Krause

    I looked into making this work for function calls with parameters today.
    The attached patch should do so at the AST level.
    But iCode generation and code generation currently still expect a function prototype with matching parameters, and would thus need work, too.

     

Log in to post a comment.

MongoDB Logo MongoDB