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
  • Hans-Bernhard,

    Yes, I made a mistake in calling this a function pointer type instead of a function type. The function type seems like the best approach since the function type is being passed in many functions and structures and it wouldn't make sense to redefine the entire function each time.

    Thank you for the suggestions and comments. I have tried to do the following:

    Write bob reentrant;
    

    The result is:

    error C158: 'bob': function contains unnamed parameter
    error C141: syntax error near 'reentrant'


    Any other suggestions would be appreciated.

Reply
  • Hans-Bernhard,

    Yes, I made a mistake in calling this a function pointer type instead of a function type. The function type seems like the best approach since the function type is being passed in many functions and structures and it wouldn't make sense to redefine the entire function each time.

    Thank you for the suggestions and comments. I have tried to do the following:

    Write bob reentrant;
    

    The result is:

    error C158: 'bob': function contains unnamed parameter
    error C141: syntax error near 'reentrant'


    Any other suggestions would be appreciated.

Children
  • The function type seems like the best approach since the function type is being passed in many functions and structures and it wouldn't make sense to redefine the entire function each time.

    This sounds like you're mighty confused about what C can do and what it can't. Maybe you've read to much stuff about the mythical, but non-existant language "C/C++", or simply confuse C++ with C here.

    There's no way at all you can pass a function around in C, nor can you put one into a structure. You can declare a function type, and even a function object, but you can't assign such objects, nor do anything much else with them. In C, that will always have to be a pointer to a function instead. Which is a major reason why you'll hardly ever see a typedef like your Writer in anybody's C sources.

    While function types formally exist, they are hardly ever actually used in a way where it would help a lot to give them a name instead of just spelling out the actual function's declaration in full. Whenever you need to do something like that, it's almost certainly a pointer-to-function you really need, anyway.