On Mar 24, 5:49 pm, "Stephen Sprunk" <step...@sprunk.org> wrote:
> "Carnage" <boyle.a...@gmail.com> wrote in message
>
> news: ups.com...
>
> >I want to provide a common platform agnostic function declaration
> > which references different implementations for different hardware
> > platforms.
>
> > What is the most type safe way to do this in 'C'?
>
> Type safety isn't the concern; it's logistics.
>
> There are two common techniques I've seen. The first is used if the
> implementations share very little in common. You create a single header
> file, e.g. mylib.h, and a separate source file for each implementation, e.g.
> mylib-posix.c, mylib-win32.c, etc. Then, you structure the build (e.g.
> Makefile) so that the appropriate file is compiled into an object that's
> always named the same, e.g. mylib.o. Then you can just blindly link in that
> file later without having to worry about which source file it was compiled
> from.
>
> The second is used if the implementations are mostly common but have a few
> critical differences. Just create one source file as normal, but break out
> the varying sections with #ifdefs, and set up the build environment so that
> the correct macro (e.g. POSIX, WIN32, etc.) is defined so that the correct
> parts of the code are compiled in.
>
> As long as the API is defined in a portable manner, you can safely put all
> sorts of evil non-portable stuff in your private implementation. Of course,
> your code will only work on systems you've written implementations for...
>
> S
>
> --
> Stephen Sprunk "Those people who think they know everything
> CCIE #3723 are a great annoyance to those of us who do."
> K5SSS --Isaac Asimov
>
> --
> Posted via a free Usenet account fromhttp://www.teranews.com
Thanks - that helped me think about my problem more clearly.