standard library structure
Posted: Sat Oct 22, 2011 1:00 pm
Hi,
Up until now, my C library has contained both my OS' API (which largely deals with filesystem stuff, I/O, and IPC) and the C standard API. Since my API needs things like dynamic memory allocation and math/string functions for its implementation, but higher level C functions like the ones in stdio.h need my API for their implementation, it seems as if they're sort of caught in a dependency cycle, which is why I have them together. I've been able to separate out my driver API into a separate library, but that's pretty much it.
However, I'm planning to write a C++ standard library in the near future, and may write some sort of POSIX wrapper library as well, and it's starting to seem like a good idea to try and separate the C standard functionality from my API more cleanly. This would also make sense if I wanted to re-implement my API in C++ or something. Of course, I then run into the dependency problem. It seems like the simplest solution is to implement clones of string.h, math.h, and stdlib.h in my API, then have the C library be a wrapper over them. This clearly adds some complexity, however, and the whole separation thing makes it so all programs have to link with two libraries in the right order.
I'm wondering what the best way to separate my API and the C library would be, and if doing so would be worth it (i.e. would make things cleaner overall and/or reduce overall complexity.)
Edit: I'm also having similar troubles separating my math library from the C library as well; things like printf("%f") require some logarithm functions, which then means programs would have to always link with libm.
Up until now, my C library has contained both my OS' API (which largely deals with filesystem stuff, I/O, and IPC) and the C standard API. Since my API needs things like dynamic memory allocation and math/string functions for its implementation, but higher level C functions like the ones in stdio.h need my API for their implementation, it seems as if they're sort of caught in a dependency cycle, which is why I have them together. I've been able to separate out my driver API into a separate library, but that's pretty much it.
However, I'm planning to write a C++ standard library in the near future, and may write some sort of POSIX wrapper library as well, and it's starting to seem like a good idea to try and separate the C standard functionality from my API more cleanly. This would also make sense if I wanted to re-implement my API in C++ or something. Of course, I then run into the dependency problem. It seems like the simplest solution is to implement clones of string.h, math.h, and stdlib.h in my API, then have the C library be a wrapper over them. This clearly adds some complexity, however, and the whole separation thing makes it so all programs have to link with two libraries in the right order.
I'm wondering what the best way to separate my API and the C library would be, and if doing so would be worth it (i.e. would make things cleaner overall and/or reduce overall complexity.)
Edit: I'm also having similar troubles separating my math library from the C library as well; things like printf("%f") require some logarithm functions, which then means programs would have to always link with libm.