2

I am building a range of C libraries to improve separation of code in a large codebase.

I would like to enforce strict separation using minimal public library interfaces.

The libraries consists of several modules (c + h files), some with internal references.

Currently, the library header files contain both prototypes related to the library interface functions and the public functions that are used internally in the library (in between the library modules).

I would like to somehow filter out the public interfaces which should not be accessible through the library interface (the internal public functions used in between the library modules).

I have come up with the following possible solutions, but I do not feel confident that any of these are optimal:

  1. Maintain two header files for each module. One header file with internal interfaces used within the library and one header file containing the public library interfaces which may be used by the users of the library
  2. Use include guards + a c pre-processor to filter out sections of the header files - with the resulting pre-processed header file only containing the library public functions
  3. Write a custom script to filter the header files based on some syntax using c-style comments e.g. // Lib func \n void function1 ( int test ); For this solution I would be using some standard tool to parse the c header files (such as clang / LibClang).

I expect that this is a standard “problem” building libraries and wonder why it is not possible to find anything on the topic on SOF or google.

Any suggestions to how this can be effectively achieved is highly appreciated.

Thanks

CSS
  • 21
  • 2

1 Answers1

-1

Also, you can use "static const func()" in this case the domain of the function will be the only current .c file. In the fact need an only static function(), but realization static const func() will be better(correct me if I'm wrong in it).

AlexK
  • 59
  • 1
  • 6
  • How does it help you with filtering out public header interface? – WindyFields Oct 25 '17 at 05:21
  • "filtering out public header interface" was only one of the possible options. qualificator `static` useful for unavailable functions outside of the file. – AlexK Oct 25 '17 at 12:54
  • Hi thanks the the reply. We naturally declare functions static when only used within a single source file. The problem is with the functions which have to be public. – CSS Oct 26 '17 at 05:54