Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Cross platform lib in 'C'

Reply
Thread Tools

Cross platform lib in 'C'

 
 
Barry
Guest
Posts: n/a
 
      03-24-2007

"user923005" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> On Mar 23, 4:30 pm, "Carnage" <(E-Mail Removed)> wrote:
>> 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'?

>
> I'm not sure if we can really believe in an agnostic function.
>


Of course dyslexic agnostic functions waffle on whether to
mallocate space for dog.


 
Reply With Quote
 
 
 
 
Carnage
Guest
Posts: n/a
 
      03-25-2007
On Mar 24, 5:49 pm, "Stephen Sprunk" <(E-Mail Removed)> wrote:
> "Carnage" <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed) 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Lib depending on Lib, packaging for distro Christopher C++ 4 11-01-2007 10:36 PM
difference between libboost_regex-mt-gd-1_33_1.lib and boost_regex-mt-gd-1_33_1.lib ideal.black@gmail.com C++ 3 09-30-2007 06:54 AM
how to debug this error? /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../lib/crt1.o Durduran C Programming 10 07-30-2007 09:03 PM
Need odbc32.lib odbccp32.lib Praetorian C++ 1 04-20-2006 07:14 PM
Diff betw common/lib and shared/lib in Tomcat James Yong Java 0 09-12-2005 02:36 AM



Advertisments