#742 Problems with bit vars as arguments

closed-fixed
5
2013-05-25
2004-04-20
No

Hi.

Using a "bit" type as a function parameter doesn't
seem to be properly supported.
I have several problems with the following code:
---
bit c=5;
void z(){}

static char f(bit a, bit b) reentrant
{
z();
return a+b+c;
}

char main()
{
return f(3, 2);
}
---

1. Trying to compile:

$ sdcc statre.c
statre.c:8: error: storage class not allowed for
automatic variable 'a' in reentrant function unless
static

But, as you can see, it is static! Am I missing
something, or is it a bug?

2. Removing "reentrant". Now it compiles, but both
the arguments are treated as "char", and the return
value is 6. Apparently "c" is handled properly, but
"a" and "b" - not. I would expect 3 at return.
IIRC older sdcc used to put the "bit" vars, even
if arguments, to a BSEG. Right now I see _f_PARM_2
in a DSEG, which doesn't look good (without z() it
is placed to an OSEG).

Discussion

  • Stas Sergeev

    Stas Sergeev - 2004-04-20

    Test case

     
  • Maarten Brock

    Maarten Brock - 2004-04-21

    Logged In: YES
    user_id=888171

    Hi Stas,

    "statre.c:8: error: storage class not allowed for
    automatic variable 'a' in reentrant function unless
    static"

    Here "static" is not about the function being (file-)static,
    which means not exported. But the variable must be static,
    which is impossible for a parameter, but a local variable could
    be.

    I've also noticed this bit-to-byte translation behaviour in
    passing bit parameters. Hadn't seen the miscalculations yet
    though (BUG). The rest about the segments is correct
    behaviour.

    Maybe bit parameters for reentrant functions could be
    transmitted in bits of A, B or a dedicated byte in BSEG which
    can be pushed/popped on stack just like any other register.
    (RFE?) Just as desirable as returning a bit from a function, I
    guess (RFE?)

    Greets,
    Maarten

     
  • Stas Sergeev

    Stas Sergeev - 2004-04-21

    Logged In: YES
    user_id=501371

    Hi.

    > Here "static" is not about the function being
    > (file-)static, which means not exported. But the
    > variable must be static,
    Oh, so it was only me being fooled by a misleading error
    message again? Even better - should be easier to fix:)
    If it writes that "bit" is not allowed as a parameter
    for reentrant funcs, that would already be better I think.

    > Maybe bit parameters for reentrant functions could be
    > transmitted in bits of A, B or a dedicated byte in BSEG
    > which can be pushed/popped on stack just like any other
    > register.
    I don't suppose this is easy to implement. I think for
    the short-term fix it would be sufficient to disallow the
    "bit" for reentrant funcs (actually only by fixing an error
    message), and handle them properly for non-reentrant ones
    (simply putting them to BSEG should fix the miscalculation,
    but I wonder what to do if that can also be placed to
    OSEG - just ignore that possibility and put to BSEG anyway?
    Let's see...)

     
  • Maarten Brock

    Maarten Brock - 2004-11-18
    • milestone: --> fixed
    • assigned_to: nobody --> maartenbrock
    • status: open --> closed-fixed
     
  • Maarten Brock

    Maarten Brock - 2004-11-18

    Logged In: YES
    user_id=888171

    Error statement was changed some time ago already. Now
    calculation problem also is fixed in SDCC 2.4.7.

     

Log in to post a comment.