Warm tip: This article is reproduced from stackoverflow.com, please click
c function types

Conflicting types error for function taking void* in public API and typed* under the hood

发布于 2020-03-27 10:23:32

I'm trying to build a 3rd party library which has a function defined in the public header as such

void reset(void* instance);

And in the implementation

void reset(instance_type* instance) {
   ...
}

And I'm getting a conflicting types compiler error. Now this seems obvious why to me on the surface. The author was using MSVC and I'm using gcc set to C99 standard - maybe that's why it worked on the authors machine? What's the minimal modification I can make to get this to build under the constraint that I don't want to expose the instance_type through the public interface?

Questioner
learnvst
Viewed
102
John Bollinger 2019-07-03 22:36

What's the minimal modification I can make to get this to build under the constraint that I don't want to expose the instance_type through the public interface?

It is necessary for the definition to agree with the declaration in the header. If you don't want to expose instance_type in the public API, then that means modifying the definition to match the header:

void reset(void* _instance) {
   instance_type* instance = _instance;
   ...
}