Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Portable C code

Reply
Thread Tools

Portable C code

 
 
Kristan Dyson
Guest
Posts: n/a
 
      10-05-2006
I was just wondering whether you knew whether it is possible to compile a
fully portable C program? I want to write a 'C' CGI program on Windows,
then just upload it to my Plus.Net Debian-based server.
As I want to write pure ANSI C, then I thought it may be possible to write a
program that would run fine on both. Having said that, surely (?), it would
have to be compiled for specific platforms, unless of course there is some
abstraction layer at runtime, like with java. Anyway, this is probably not
possible now I have thought about it.


But I would love to know what you guys and gals think?!



Cheers,

Kristan


 
Reply With Quote
 
 
 
 
Gordon Burditt
Guest
Posts: n/a
 
      10-05-2006
>I was just wondering whether you knew whether it is possible to compile a
>fully portable C program? I want to write a 'C' CGI program on Windows,
>then just upload it to my Plus.Net Debian-based server.


Source code is portable. Executables are not. It is quite possible
that an executable on one OS is not recognized as an executable on
another, even if they are running on the actual same CPU (which
dual-boots different OSs). And even if it is, it may not run correctly.

>As I want to write pure ANSI C, then I thought it may be possible to write a
>program that would run fine on both.


Compile it on both.

>Having said that, surely (?), it would
>have to be compiled for specific platforms, unless of course there is some
>abstraction layer at runtime, like with java. Anyway, this is probably not
>possible now I have thought about it.
>
>
>But I would love to know what you guys and gals think?!

 
Reply With Quote
 
 
 
 
Richard Heathfield
Guest
Posts: n/a
 
      10-05-2006
[Followups set to comp.lang.c, since I don't suppose the Microsoft people
are all that interested in portability]

Kristan Dyson said:

> I was just wondering whether you knew whether it is possible to compile a
> fully portable C program?


That depends on what you mean by "fully portable", of course. But it's
certainly possible to have a very, very portable C program.

What is not possible, alas, is to have one binary that runs on any platform
you like - no matter what language it's written in.

So you do need a compiler on each platform (or group of binary-compatible
platforms) that you wish to support.

> I want to write a 'C' CGI program on Windows,
> then just upload it to my Plus.Net Debian-based server.
> As I want to write pure ANSI C, then I thought it may be possible to write
> a program that would run fine on both.


Well, the point of writing it in pure ANSI C is so that you can compile the
source code without first having to customise it to a particular platform.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
 
Reply With Quote
 
=?ISO-8859-1?Q?=22Nils_O=2E_Sel=E5sdal=22?=
Guest
Posts: n/a
 
      10-05-2006
Kristan Dyson wrote:
> I was just wondering whether you knew whether it is possible to compile a
> fully portable C program? I want to write a 'C' CGI program on Windows,
> then just upload it to my Plus.Net Debian-based server.
> As I want to write pure ANSI C, then I thought it may be possible to write a
> program that would run fine on both. Having said that, surely (?), it would
> have to be compiled for specific platforms, unless of course there is some
> abstraction layer at runtime, like with java. Anyway, this is probably not
> possible now I have thought about it.

It depends on what the CGI program must do.
If it can accomplish its goal by standard C, go for it.
CGI programs typically only reads from stdin, writes
to stdout which surly can be done in standard C.
Care must be taken on how you handle and convert
input/output data though.

If you need other features - sockets, database access, etc.
it is not, but perhaps you can find third party packages for
such things that atleast are portable among the systems you
want to support.
 
Reply With Quote
 
Elijah Cardon
Guest
Posts: n/a
 
      10-05-2006

"Richard Heathfield" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> [Followups set to comp.lang.c, since I don't suppose the Microsoft people
> are all that interested in portability]

snip
There is nothing quite as stationary as an island, e.g. England. It is c
that doesn't talk to MS, not the other way around. EC


 
Reply With Quote
 
Chris Dollin
Guest
Posts: n/a
 
      10-05-2006
Elijah Cardon wrote:

> "Richard Heathfield" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> [Followups set to comp.lang.c, since I don't suppose the Microsoft people
>> are all that interested in portability]

> snip
> There is nothing quite as stationary as an island, e.g. England.


Eh?

> It is c that doesn't talk to MS, not the other way around. EC


C doesn't talk /at all/. Neither does it eat, or write three-volume
novels, nor snore at twenty-seven minutes past three in the morning.

Unpack?

--
Chris "falling further in" Dollin
"No-one here is exactly what he appears." G'kar, /Babylon 5/

 
Reply With Quote
 
Kristan
Guest
Posts: n/a
 
      10-05-2006
Thank you all for your help! Hopefully, I will one day know enough about C
/ C++ to return the favour

cheers
kristan

"Kristan Dyson" <(E-Mail Removed)> wrote in message
news:4524efa1$0$24467$(E-Mail Removed)...
>I was just wondering whether you knew whether it is possible to compile a
>fully portable C program? I want to write a 'C' CGI program on Windows,
>then just upload it to my Plus.Net Debian-based server.
> As I want to write pure ANSI C, then I thought it may be possible to write
> a program that would run fine on both. Having said that, surely (?), it
> would have to be compiled for specific platforms, unless of course there
> is some abstraction layer at runtime, like with java. Anyway, this is
> probably not possible now I have thought about it.
>
>
> But I would love to know what you guys and gals think?!
>
>
>
> Cheers,
>
> Kristan
>
>



 
Reply With Quote
 
John Smith
Guest
Posts: n/a
 
      10-05-2006
Kristan Dyson wrote:

> I was just wondering whether you knew whether it is possible to compile a
> fully portable C program? I want to write a 'C' CGI program on Windows,
> then just upload it to my Plus.Net Debian-based server.


You would need to upload the source code and then recompile on the
server to generate new binary executables. If don't have shell access,
or if there is no compiler on the server, you may be screwed.

That's probably one of the things that makes an interpreted language
like Perl more popular for CGI stuff. Install a Windows version of Perl
(ActivePerl ??), monkey with your scripts until they work, then just put
them in proper place on the server.


 
Reply With Quote
 
quarkLore
Guest
Posts: n/a
 
      10-06-2006

John Smith wrote:
> Kristan Dyson wrote:
>
> > I was just wondering whether you knew whether it is possible to compile a
> > fully portable C program? I want to write a 'C' CGI program on Windows,
> > then just upload it to my Plus.Net Debian-based server.

>

I don't know much about that
> You would need to upload the source code and then recompile on the
> server to generate new binary executables. If don't have shell access,
> or if there is no compiler on the server, you may be screwed.
>

People have told, make the source code portable, binaries are not
portable.

> That's probably one of the things that makes an interpreted language
> like Perl more popular for CGI stuff. Install a Windows version of Perl
> (ActivePerl ??), monkey with your scripts until they work, then just put
> them in proper place on the server.

Perl is good for CGI. So decide early to go for perl/script type
thingies or a full fledged programming language like C.

How to make portable code in C:

1. Have an indepth knowledge of features in ANSI-C. (Not just internals
in C)
2. Study the compilers on platforms you are working in. Different
compilers may or may not support all the features of ANSI-C
3. Try not to use dirty hacks, though great, they are often device
specific
4. Then the lame stuff: design your program logic independent of OS. So
divide device/platform specific code to the logical part of it. e.g.
Don't directly assume fopen would be available created a wrapper for
it.

These are just starters if you are new to making code portable.

 
Reply With Quote
 
Walter Roberson
Guest
Posts: n/a
 
      10-06-2006
In article <c4dVg.3188$(E-Mail Removed)>,
John Smith <(E-Mail Removed)> wrote:
>Kristan Dyson wrote:


>> I was just wondering whether you knew whether it is possible to compile a
>> fully portable C program? I want to write a 'C' CGI program on Windows,
>> then just upload it to my Plus.Net Debian-based server.


>You would need to upload the source code and then recompile on the
>server to generate new binary executables. If don't have shell access,
>or if there is no compiler on the server, you may be screwed.


There are cross-compilers available in limited cases.


>That's probably one of the things that makes an interpreted language
>like Perl more popular for CGI stuff. Install a Windows version of Perl
>(ActivePerl ??), monkey with your scripts until they work, then just put
>them in proper place on the server.


No, Perl turns out to relatively *not* portable. For more words
on this subject, please see my earlier posting,
http://groups.google.ca/group/comp.l...4fa97697731535
--
Okay, buzzwords only. Two syllables, tops. -- Laurie Anderson
 
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
Portable Python - free portable development environment ! perica.zivkovic@gmail.com Python 7 01-13-2007 11:19 AM
portable (VHDL) vs. non-portable (altera LPM) approaches to signed computations Eli Bendersky VHDL 1 03-01-2006 02:43 PM
naming for fun --- write portable java code Shin Java 5 11-16-2005 06:22 PM
code free portable dvd player with monitor built-in vdeo_guy DVD Video 2 02-27-2004 02:53 PM
Looking for portable C++ code The Saqe C++ 3 09-24-2003 05:41 AM



Advertisments