473,769 Members | 2,245 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Writing portable software

Dear C group,

I'm very interested in writing portable C, but I only have GNU, Sparc
and Cygwin to compile on.

What I find is the biggest problem to writing portable C is what headers
to include. What sites do people know about that are comprehensive in
their differences?

For example, MacOSX complained about <string.h>. With Solaris I needed
to include another header file other than <fcntrl.h> to get definitions
for changing the nonblocking status of reading/writing files.

If there is a definitive guide between "modern" systems, this would be
very helpful.

TIA.
Jason.
Nov 14 '05 #1
10 2185
Jason Curl wrote:
Dear C group,

I'm very interested in writing portable C, but I only have GNU, Sparc
and Cygwin to compile on.

What I find is the biggest problem to writing portable C is what headers
to include. What sites do people know about that are comprehensive in
their differences?

For example, MacOSX complained about <string.h>. With Solaris I needed
to include another header file other than <fcntrl.h> to get definitions
for changing the nonblocking status of reading/writing files.

If there is a definitive guide between "modern" systems, this would be
very helpful.

TIA.
Jason.


The simplest answer is to adhere to some standard and perhaps the best
choice is one of the ANSI standards. With gcc you can use the
-std=standard option to define which standard to use.

IAn
--
Ian Bell
Nov 14 '05 #2
Jason Curl <j_********@mot orola.com> wrote:
I'm very interested in writing portable C, but I only have GNU, Sparc
and Cygwin to compile on. What I find is the biggest problem to writing portable C is what headers
to include. What sites do people know about that are comprehensive in
their differences?
The C standard(s) list all include files that you can protably use. For
C89 these are

<assert.h> <locale.h> <stddef.h>
<ctype.h> <math.h> <stdio.h>
<errno.h> <setjmp.h> <stdlib.h>
<float.h> <signal.h> <string.h>
<limits.h> <stdarg.h> <time.h>

and C99 adds the following

<complex.h> <iso646.h> <tgmath.h>
<fenv.h> <stdbool.h> <wchar.h>
<inttypes.h> <stdint.h> <wctype.h>
For example, MacOSX complained about <string.h>.
Then the compiler isn't standard compliant and you have no chance
to write anything portably.
With Solaris I needed
to include another header file other than <fcntrl.h> to get definitions
for changing the nonblocking status of reading/writing files.
Standard C doesn't allow you to set a "non-blocking" status - you
must already be using some non-standard functions (like open() or
fcntl() etc.) to be able to do that.
If there is a definitive guide between "modern" systems, this would be
very helpful.


It's not a question which system you're using but you must restrict
yourself to what the C standard specifies. If you don't mean portable
in a C sense, there are also other standards, so you can write portable
programs e.g. as far as the POSIX standard goes, but then you should
ask in e.g. comp.unix.progr ammer.
Regards, Jens
--
\ Jens Thoms Toerring ___ Je***********@p hysik.fu-berlin.de
\______________ ____________ http://www.toerring.de
Nov 14 '05 #3
On Mon, 14 Mar 2005 15:30:33 +0100, Jason Curl
<j_********@mot orola.com> wrote:
I'm very interested in writing portable C, but I only have GNU, Sparc
and Cygwin to compile on.

What I find is the biggest problem to writing portable C is what headers
to include. What sites do people know about that are comprehensive in
their differences?


It's a little OT, but I've found GNU Autoconf and Automake invaluable
for this sort of thing. It doesn't solve the problem, but it does
make handling the problem much easier.

You're right that finding which header files to include is one of the
big problems, but it's not the only one. You'll probably find that
some OSes don't have all the functions that you need, so you need to
write replacements (e.g. Linux has getopt_long_onl y, but FreeBSD
doesn't).

Roy

Nov 14 '05 #4
In article <39************ *@uni-berlin.de>,
<Je***********@ physik.fu-berlin.de> wrote:
For example, MacOSX complained about <string.h>.
Then the compiler isn't standard compliant and you have no chance
to write anything portably.


Thousands, probably millions, of programs are compiled using
<string.h> every day. The OP's real problem must be something else.

-- Richard
Nov 14 '05 #5
Richard Tobin <ri*****@cogsci .ed.ac.uk> wrote:
In article <39************ *@uni-berlin.de>,
<Je***********@ physik.fu-berlin.de> wrote:
For example, MacOSX complained about <string.h>.
Then the compiler isn't standard compliant and you have no chance
to write anything portably.

Thousands, probably millions, of programs are compiled using
<string.h> every day. The OP's real problem must be something else.


I heard that there are some systems tha have a <strings.h> instead
of the correct <string.h> - perhaps MacOSX is one of them, I can't
tell since I never used it. It would be good if the OP would cite
the full error message was, otherwise it's all guesswork.

Regards, Jens
--
\ Jens Thoms Toerring ___ Je***********@p hysik.fu-berlin.de
\______________ ____________ http://www.toerring.de
Nov 14 '05 #6
In article <39************ *@uni-berlin.de>,
<Je***********@ physik.fu-berlin.de> wrote:
I heard that there are some systems tha have a <strings.h> instead
of the correct <string.h> - perhaps MacOSX is one of them
No, MacOS X has a perfectly good string.h (it also has strings.h which
was the traditional BSD name, but that just #includes <string.h>).
It would be good if the OP would cite
the full error message was, otherwise it's all guesswork.


Yes!

-- Richard
Nov 14 '05 #7
Jason Curl wrote:
Dear C group,

I'm very interested in writing portable C, but I only have GNU, Sparc
and Cygwin to compile on.
Good, because portable C is what we specialise in here.
What I find is the biggest problem to writing portable C is what headers
to include. What sites do people know about that are comprehensive in
their differences?
It depends on how portable you want to be. Portability here generally
means sticking to ISO standard C and, due to the lack of C99 compilers,
sticking to the old C90 standard. I would suggest the FAQ for
comp.lang.c and buying a copy of K&R2 would be a good start. Note that
ONE chapter of K&R2 is not portable because it is talking about Unix,
but the rest is portable.

If you want to go beyond what ISO C requires, then you need to decide
what systems you want to be portable to and whether they follow any
common standard such as POSIX, but any such standard are off topic here.
For example, MacOSX complained about <string.h>.
It should not complain about string.h since that is an ISO standard
header. Query that on a MacOSX group.
With Solaris I needed
to include another header file other than <fcntrl.h> to get definitions
for changing the nonblocking status of reading/writing files.
That is beyond what ISO C provides, so you will have to decide what
systems you want to be portable to and see if there is a common standard.
If there is a definitive guide between "modern" systems, this would be
very helpful.


There is probably no definitive guide for things outside ISO C that I am
aware of since Windows and *nix are rather different. However, there are
libraries ported to a number of systems that can help with portability.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Nov 14 '05 #8
Jason Curl <j_********@mot orola.com> wrote:
Dear C group, I'm very interested in writing portable C, but I only have GNU, Sparc
and Cygwin to compile on. What I find is the biggest problem to writing portable C is what headers
to include. What sites do people know about that are comprehensive in
their differences?
http://oakroadsystems.com/tech/c-predef.htm
For example, MacOSX complained about <string.h>. With Solaris I needed
to include another header file other than <fcntrl.h> to get definitions
for changing the nonblocking status of reading/writing files.
These are Unix'ish systems. Interfaces exposing things like "changing the
nonblock status of reading/writing files" is not portable C, though is
generally portable among Unix systems (and most definitely not portable
between Unix and Windows). Most Unices generally expose their common
interfaces according to the Standard Unix Specification.

http://www.opengroup.org/onlinepubs/009695399/toc.htm.

You're supposed to first fill out this harmless form before viewing the
specification.

http://www.opengroup.org/online-pubs...9775&FORM=HTML
If there is a definitive guide between "modern" systems, this would be
very helpful.


None other than the C standards. For the "fun" stuff you have to become
platform specific, and the Unix platform is about as general as you can get
without being forced to delve into platform specific stuff. (I suppose that
follows from my definition of general.)

A good Unix group is comp.unix.progr ammer.
Nov 14 '05 #9
Flash Gordon wrote:
Jason Curl wrote:
Dear C group,

I'm very interested in writing portable C, but I only have GNU, Sparc
and Cygwin to compile on.

Good, because portable C is what we specialise in here.
What I find is the biggest problem to writing portable C is what
headers to include. What sites do people know about that are
comprehensive in their differences?

It depends on how portable you want to be. Portability here generally
means sticking to ISO standard C and, due to the lack of C99 compilers,
sticking to the old C90 standard. I would suggest the FAQ for
comp.lang.c and buying a copy of K&R2 would be a good start. Note that
ONE chapter of K&R2 is not portable because it is talking about Unix,
but the rest is portable.


I've read K&R 2 a long time ago and staying to the C90 standard I agree
is the best.

If you want to go beyond what ISO C requires, then you need to decide
what systems you want to be portable to and whether they follow any
common standard such as POSIX, but any such standard are off topic here.
For example, MacOSX complained about <string.h>.

It should not complain about string.h since that is an ISO standard
header. Query that on a MacOSX group.


Sorry - I don't have MacOSX, a friend of mine has and he compiled
something for me. The solution to the problem was including another
header file, don't remember exactly what - strings.h or string.h.
> With Solaris I needed
to include another header file other than <fcntrl.h> to get
definitions for changing the nonblocking status of reading/writing files.

That is beyond what ISO C provides, so you will have to decide what
systems you want to be portable to and see if there is a common standard.


Any suggestions of other newsgroups I could ask? I guess specific
newsgroups would only give me information specific to a compiler or
platform, but what is really needed is some kind of comparison list.
I've seen that GNU AutoConf tools documentation contains a small list.
If there is a definitive guide between "modern" systems, this would be
very helpful.

There is probably no definitive guide for things outside ISO C that I am
aware of since Windows and *nix are rather different. However, there are
libraries ported to a number of systems that can help with portability.


Narrowing down the search, if we remove "Windows" and go for POSIX-like
systems (e.g. QNX, BSD, GNU, Cygwin, MacOSX).

But most of all, thanks for the help so far.
Nov 14 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2474
by: aaronfude | last post by:
Hi, Perhaps this is slightly offtopic. Coming into the Windows world from Unix. Is there a reference on writing C++ libraries in a portable way. For example, right now I'm sticking "__declspec(dllexport)" in front of each of my classes. I guess I can still make it work on Unix bydefing
385
17293
by: Xah Lee | last post by:
Jargons of Info Tech industry (A Love of Jargons) Xah Lee, 2002 Feb People in the computing field like to spur the use of spurious jargons. The less educated they are, the more they like extraneous jargons, such as in the Unix & Perl community. Unlike mathematicians, where in mathematics there are no fewer jargons but each and every one are
5
7629
by: Richard Giuly | last post by:
Hello, I would like to write "portable" C++ code that could theoretically run on linux, windows, and other platforms, and I'd like to use VS as the editor/compiler/linker. The simplest thing that seems to complie in VS is this: //VS example #include "stdafx.h"
89
3862
by: Skybuck Flying | last post by:
Hello, This morning I had an idea how to write Scalable Software in general. Unfortunately with Delphi 2007 it can't be done because it does not support operating overloading for classes, or record inheritance (records do have operator overloading) The idea is to write a generic integer class with derived integer classess for 8 bit, 16 bit, 32 bit, 64 bit and 64 bit emulated.
7
1877
by: jacob navia | last post by:
There are some people here (let's call them "regulars" for short) that are always giving lessons to people about how easy is to write portable code, etc. They always point fingers at you telling you how bad you write code. One of them (I would say the prototype of them) is Heathfield. Here is an exchange that happened just a few hours ago, that demonstrates my point:
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10215
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10049
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9865
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7410
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5307
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3964
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3564
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.