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
  • "I am porting some code to an 8051.

    typedef int     (Writer) (int ,
                                       u_char * ,
                                       u_char ,
                                       size_t ,
                                       u_char * ,
                                       int *) reentrant;


    Now would be a good time to do away with using int, then.

    I would also prefer to use a more explicit name that "u_char" - my preferred names are
    U8, U16, U32, etc for Unsigned 8-bit, 16-bit, 32-bit, etc;
    S8, S16, S32, etc for Signed 8-bit, 16-bit, 32-bit, etc.
    These are explicit, concise & precise!

  • Check out:
    http://www.keil.com/support/docs/2066.htm

    An excerpt....


    When parameters passed to a function via a function pointer will not fit into registers, the compiler cannot determine where in memory to place the parameters since the function is not known at call-time......

    Solution #1
    Create reentrant functions using the reentrant function attribute. The compiler simulates a stack-based architecture which makes it possible to pass a virtually unlimited number of parameters to indirectly called functions.


    The other solution is to change functions parameters so that they fit into CPU registers. I may eventually do this, but right now I am creating a prototype and I just need the code to work.

Reply
  • Check out:
    http://www.keil.com/support/docs/2066.htm

    An excerpt....


    When parameters passed to a function via a function pointer will not fit into registers, the compiler cannot determine where in memory to place the parameters since the function is not known at call-time......

    Solution #1
    Create reentrant functions using the reentrant function attribute. The compiler simulates a stack-based architecture which makes it possible to pass a virtually unlimited number of parameters to indirectly called functions.


    The other solution is to change functions parameters so that they fit into CPU registers. I may eventually do this, but right now I am creating a prototype and I just need the code to work.

Children
More questions in this forum