Re: portable C, posix C and windows C
- From: John Bode <jfbode1029@xxxxxxxxx>
- Date: Thu, 9 Oct 2008 11:37:22 -0700 (PDT)
On Oct 8, 12:34 am, asit <lipu...@xxxxxxxxx> wrote:
what is the difference between portable C, posix C and windows C ???
"Portable" has several different meanings with respect to C. One
meaning is that C compilers have been implemented on a wide variety of
platforms where other languages have not; this was a Big Deal back in
the dark ages, now probably not so much. Another meaning is that
there is a single, well-known standard for the C language that most
compilers implement faithfully, as opposed to languages that vary
depending on the platform and vendor (there were multiple, slightly
incompatible versions of Pascal and Fortran floating around when C was
first becoming popular).
For most of us, "portable" means C code that has been written in such
a way that it will build and run on multiple platforms with little or
no change. For example, the canonical "Hello World" program
#include <stdio.h>
int main(void)
{
printf("Hello, World\n");
return 0;
}
should compile and run and give the same results on every platform
without making any changes to the source code, so it's considered
"portable" (what I call trivially portable). As long as your source
code makes no assumptions about word size, byte order, or numerical
representation, and restricts itself to using the standard library
(stdio, stdlib, string, math, etc.), then it should be trivially
portable like the code above.
Unfortunately, C doesn't provide built-in support for a lot of
capabilities that most of us have come to expect in modern software --
graphics, sound, network support, etc., so to do any of that we have
to rely on vendor-specific or third-party libraries that may only
exist on specific platforms. For example, if you took the source code
for Microsoft Word for Windows and tried to compile and run in on a
Mac, you'd get a ton of errors because the Mac doesn't support the
Windows libraries. In this case, "portable" means structuring your
code so that the stuff that really is platform-specific is segregated
from the general application logic, so that the general application
logic can be ported easily from one platform to another.
There is no POSIX-specific version of the C language; when people talk
about POSIX C, they're talking about C code that uses interfaces and
utilities defined by the POSIX standard.
Similarly, "Windows C" refers to C code that makes use of interfaces
and utilities specific to the Microsoft Windows platform, although MS
did extend the language a bit (adding extra keywords) to support
Windows programming.
.
- References:
- portable C, posix C and windows C
- From: asit
- portable C, posix C and windows C
- Prev by Date: Re: Way to view public function names in a library
- Next by Date: Re: Way to view public function names in a library
- Previous by thread: Re: portable C, posix C and windows C
- Next by thread: Memory allignment/type casting question
- Index(es):
Relevant Pages
|