This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

adding reentrant to typedef function pointers causes redefinition in code

I am porting some code to an 8051.

(header.h)

typedef int     (Writer) (int ,
                                   u_char * ,
                                   u_char ,
                                   size_t ,
                                   u_char * ,
                                   int *) reentrant;
(source.h)
Writer bob;

(source.c)
.
.
.
int     bob(int val1,
            u_char * dat1,
            u_char dat2,
            size_t val2,
            u_char * dat3,
            int *pval) reentrant
{
}

When I attempt to compiler this, I get
error C231: '_bob' : redefinition. If I go to source.h and do the following:
(source.h)
//Comment out Writer bob;
int     (bob)(int val1,
            u_char * dat1,
            u_char dat2,
            size_t val2,
            u_char * dat3,
            int *pval) reentrant;


It compiles fine. Is this a limitation of the compiler? Any shortcuts I could use so I don't have to rewrite large chunks of code

Parents
  • Do you already have this code running on some other platform?
    If so, might it not be easier to re-engineer it on that platform to do away with the need for these problematic (for C51) function pointers, and then port the resulting C51-friendly code to the 8051?

    Or is this some so-called "portable" reference code that you're trying to get onto C51?
    Again, might it be easier to start by implementing it on a more conventional, C-friendly, target (eg, a PC) first, and then proceed as above?

    Just a thought - it's worked for me before.

Reply
  • Do you already have this code running on some other platform?
    If so, might it not be easier to re-engineer it on that platform to do away with the need for these problematic (for C51) function pointers, and then port the resulting C51-friendly code to the 8051?

    Or is this some so-called "portable" reference code that you're trying to get onto C51?
    Again, might it be easier to start by implementing it on a more conventional, C-friendly, target (eg, a PC) first, and then proceed as above?

    Just a thought - it's worked for me before.

Children
  • This is code that runs on windows, but was written in a portable manner. I am using the windows version quite a bit for reference.

    I could go back to windows, but the problem is that I will inevitably have to deal with the C51 issues and I have so far opted to face them head on. (my head hurts!) It hasn't been bad so far except for the reentrant attribute.

    Thanks for the suggestions.......

  • "This is code that runs on windows, but was written in a portable manner."

    Trouble is, C51 is an unconventional implementation of 'C' - particularly the way that it does not use the hardware stack for function parameters & locals.
    Conventional 'C' functions are inherently reentrant; C51 functions are inherently non-reentrant.

    Therefore, even the best-designed "portable" 'C' that relies on reentrant functions (as found in 99% of 'C' implementations) will break on C51. :-(

    "I could go back to windows, but the problem is that I will inevitably have to deal with the C51 issues"

    Absolutely - but couldn't that be biting off too much at once?

    I'm just suggesting that you take it a step at a time:
    First, stick with the familiar, conventional Windows environment and remove the reentrancy requirement;
    Then, when you know you've got it working non-reentrant, move it to C51 and address all the other issues (word size, byte ordering, etc, etc)