473,883 Members | 1,618 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

code portability

My question is more generic, but it involves what I consider ANSI standard C
and portability.

I happen to be a system admin for multiple platforms and as such a lot of
the applications that my users request are a part of the OpenSource
community. Many if not most of those applications strongly require the
presence of the GNU compiling suite to work properly. My assumption is that
this is due to the author/s creating the applications with the GNU suite.
Many of the tools requested/required are GNU replacements for make,
configure, the loader, and lastly the C compiler itself. Where I'm going
with this is, has the OpenSource community as a whole committed itself to at
the very least encouraging its contributing members to conform to ANSI
standards of programming?

My concern is that as an admin I am sometimes compelled to port these
applications to multiple platforms running the same OS and as the user
community becomes more and more insistent on OpenSource applications will
gotcha's appear due to lack of portability in coding? I fully realize that
independent developers may or may not conform to standards, but again is it
at least encouraged?

11.32 of the FAQ seemed to at least outline the crux of what I am asking.
If I loaded up my home machine to the gills will all open source compiler
applications (gcc, imake, autoconfig, etc....) would my applications that I
compile and link and load conform?
Aug 1 '06 #1
239 10386

Eigenvector wrote:
My question is more generic, but it involves what I consider ANSI standard C
and portability.

I happen to be a system admin for multiple platforms and as such a lot of
the applications that my users request are a part of the OpenSource
community. Many if not most of those applications strongly require the
presence of the GNU compiling suite to work properly. My assumption is that
this is due to the author/s creating the applications with the GNU suite.
Many of the tools requested/required are GNU replacements for make,
configure, the loader, and lastly the C compiler itself. Where I'm going
with this is, has the OpenSource community as a whole committed itself to at
the very least encouraging its contributing members to conform to ANSI
standards of programming?
GCC attempts to conform to C90 and C99 and in many regards it's there.
If you disable GNU extensions [or just plain don't use them, cuz if
you're not writing a kernel you probably don't need them] you're pretty
much set.
My concern is that as an admin I am sometimes compelled to port these
applications to multiple platforms running the same OS and as the user
community becomes more and more insistent on OpenSource applications will
gotcha's appear due to lack of portability in coding? I fully realize that
independent developers may or may not conform to standards, but again is it
at least encouraged?
The C library [glibc] and other libs [pthreads, sockets, etc] follow
various UNIX, POSIX and ANSI standards. There are minor gotchas (for
instance, pthreads is part of the glibc in Linux but not in other
UNIXes) but for the most part source compatibility is there.
11.32 of the FAQ seemed to at least outline the crux of what I am asking.
If I loaded up my home machine to the gills will all open source compiler
applications (gcc, imake, autoconfig, etc....) would my applications that I
compile and link and load conform?
Read the man pages. Make sure the functions you use conform to some
standard and are not specific to your OS (e.g. not Linux only).

You'd be surprised how much of the standard libraries are API
consistent across UNIX, BSD and Linux.

Tom

Aug 1 '06 #2

"Tom St Denis" <to********@gma il.comwrote in message
news:11******** **************@ m73g2000cwd.goo glegroups.com.. .
>
Eigenvector wrote:
>My question is more generic, but it involves what I consider ANSI
standard C
and portability.

I happen to be a system admin for multiple platforms and as such a lot of
the applications that my users request are a part of the OpenSource
community. Many if not most of those applications strongly require the
presence of the GNU compiling suite to work properly. My assumption is
that
this is due to the author/s creating the applications with the GNU suite.
Many of the tools requested/required are GNU replacements for make,
configure, the loader, and lastly the C compiler itself. Where I'm going
with this is, has the OpenSource community as a whole committed itself to
at
the very least encouraging its contributing members to conform to ANSI
standards of programming?

GCC attempts to conform to C90 and C99 and in many regards it's there.
If you disable GNU extensions [or just plain don't use them, cuz if
you're not writing a kernel you probably don't need them] you're pretty
much set.
What about the programmers who submit to the archives? That is mainly where
I see massive gcc and imake requirements. In fact I have on occassion
attempted to compile applications - such as gcc using my native Intel or xlC
compilers without luck. Again this isn't a question on how to compile GCC,
but rather is the experience that the OpenSource community tries to conform
to ANSI standards?
>
>My concern is that as an admin I am sometimes compelled to port these
applications to multiple platforms running the same OS and as the user
community becomes more and more insistent on OpenSource applications will
gotcha's appear due to lack of portability in coding? I fully realize
that
independent developers may or may not conform to standards, but again is
it
at least encouraged?

The C library [glibc] and other libs [pthreads, sockets, etc] follow
various UNIX, POSIX and ANSI standards. There are minor gotchas (for
instance, pthreads is part of the glibc in Linux but not in other
UNIXes) but for the most part source compatibility is there.
>11.32 of the FAQ seemed to at least outline the crux of what I am asking.
If I loaded up my home machine to the gills will all open source compiler
applications (gcc, imake, autoconfig, etc....) would my applications that
I
compile and link and load conform?

Read the man pages. Make sure the functions you use conform to some
standard and are not specific to your OS (e.g. not Linux only).

You'd be surprised how much of the standard libraries are API
consistent across UNIX, BSD and Linux.

Tom

Aug 1 '06 #3
Eigenvector said:

<snip>
Where I'm going
with this is, has the OpenSource community as a whole committed itself to
at the very least encouraging its contributing members to conform to ANSI
standards of programming?
I doubt it very much, unfortunately.
My concern is that as an admin I am sometimes compelled to port these
applications to multiple platforms running the same OS and as the user
community becomes more and more insistent on OpenSource applications will
gotcha's appear due to lack of portability in coding?
It's entirely possible that they will. Unfortunately, open source code is
not, generally speaking, known for its robustness or portability. In fact,
I can think of only one kind of source base that is less robust and less
portable than open source code - and that's closed source code.
I fully realize
that independent developers may or may not conform to standards, but again
is it at least encouraged?
We do our bit, here in comp.lang.c, but I doubt whether it's enough to make
more than a small difference.

--
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)
Aug 1 '06 #4
Eigenvector wrote:
What about the programmers who submit to the archives? That is mainly where
I see massive gcc and imake requirements. In fact I have on occassion
attempted to compile applications - such as gcc using my native Intel or xlC
compilers without luck. Again this isn't a question on how to compile GCC,
but rather is the experience that the OpenSource community tries to conform
to ANSI standards?
GCC is hardly your average OSS project (and Intel C is hardly standard
conforming).

Generally if you don't use any special features of GNU make you should
be "make portable". My makefiles are used in windows, linux, bsd, AIX,
HP-UX, MacOS, etc, etc, etc even though they split between proprietary
make, imake, gmake, etc, etc, etc.

Aim for C89 compliance and you pretty much got things nailed. Keep in
mind that many compilers supported various C99 features even back then.
E.g., long long has been supported for a while and ALL unix C
compilers I've seen support it [even the ones released in the mid 90s].

Avoid VLAs, // comments and the newer header files if you want the
widest possible reach.
Tom

Aug 1 '06 #5
Tom St Denis wrote:
Avoid VLAs, // comments and the newer header files if you want the
widest possible reach.
Tom
You should also avoid long long. This did not exist in C89.

To add 64 bit quantities you should develop and use
add64bits(a,b);
sub64bits(a,b);
mult64bits(a,b) ;

etc ad nauseum.

You should also avoid long double. This did not exist in C89.

To add two long doubles you should develop and use a package
with extended floating point precision.

addlongdouble(a ,b);
sublongdouble(a ,b);

ad nauseum.
You should not have any array that goes beyond 32K. The size
of an integer should not be bigger than 16 bits, because that
is the minimum required by C89 if I remember correctly.

This is very easy to do: make a linked list of 32K chunks and you can
have (GASP!) arrays of maybe a MB... You should not write
int array[65000];

int m = array[45765];

but
ArrayList *newintArrayLis t(65000);
m = getintItem(arra y,45765U);

For doubles you write

ArrayList *newdoubleArray List(65000);
m = getdoubleItem(a rray,45765U);

If you want indexes bigger than 65535 you should develop a 32 bit
integer package.

And after you have developed all that you can (GASP!!!) develop your
application if you have any time left.
Obviously you should buy the new Intel biprocessor or the AMD Quad
processor to handle all that overhead but who cares? Your program
will be portable to the embedded processor in the WC...
:-)
Aug 1 '06 #6
jacob navia <ja***@jacob.re mcomp.frwrote:
You should also avoid long double. This did not exist in C89.
Oh, look, isn't it just *darling*? I'd ask if we could keep it, but
frankly I'd prefer if it kept it and its rampant lack of knowledge about
C to itself.

Richard
Aug 1 '06 #7
Richard Bos wrote:
jacob navia <ja***@jacob.re mcomp.frwrote:

>>You should also avoid long double. This did not exist in C89.


Oh, look, isn't it just *darling*? I'd ask if we could keep it, but
frankly I'd prefer if it kept it and its rampant lack of knowledge about
C to itself.

Richard
Nothing to the other points *darling* ?

Aug 1 '06 #8

jacob navia wrote:
Tom St Denis wrote:
Avoid VLAs, // comments and the newer header files if you want the
widest possible reach.
Tom

You should also avoid long long. This did not exist in C89.
Except it is valid "C" and many [most] C compilers do in fact support
it. In fact the only compiler I know of in productive use on 32/64 bit
boxes that doesn't is MSVC and there is a simple workaround (it has a
64-bit type just not called long long0.

So your "advice" is ignorant ranting lunatic bullshit.
To add 64 bit quantities you should develop and use
add64bits(a,b);
sub64bits(a,b);
mult64bits(a,b) ;
Or ... not use crappy toy compilers.

All UNIX CC's I've seen support it. GCC supports it [since well before
C99], MSVC even supports it (indirectly).

Your comment is not well founded.
You should also avoid long double. This did not exist in C89.
You should avoid floats entirely if you want portable code. Many
modern platforms don't have FPUs at all.

So unless your code really needs it you shouldn't use them.
You should not have any array that goes beyond 32K. The size
of an integer should not be bigger than 16 bits, because that
is the minimum required by C89 if I remember correctly.
12345676UL

That's valid C89. Shut the fuck up.

Array indecies only have to be of integer type. Chances are, if your
platform only supports 32K or 64K arrays you don't have that much
memory to work with anyways. So it's moot.

No amount of unportable coding will give you 1MB of ram on an 8051
(typically 8051s don't use much if any bank switching in the field....)
And after you have developed all that you can (GASP!!!) develop your
application if you have any time left.
Bullshit. It's totally valid to do

char *p = malloc(100000L * sizeof(*p));

then do p[45000] = 3;

If and only if p != NULL.

A platform may not support such requests (e.g. if segments were 32KB
for instance) and reject the malloc request. It's true that the
compiler doesn't have to support large objects, but that's an OPTIONAL
limitation only imposed when the PHYSICAL limitations of the platform
makes it troublesome to work around it.
Obviously you should buy the new Intel biprocessor or the AMD Quad
processor to handle all that overhead but who cares? Your program
will be portable to the embedded processor in the WC...
For someone who develops for windows you seem to have an odd view of
"overhead" and waste....

Tom

Aug 1 '06 #9
Tom St Denis wrote:
jacob navia wrote:
>>Tom St Denis wrote:
>>>Avoid VLAs, // comments and the newer header files if you want the
widest possible reach.
Tom

You should also avoid long long. This did not exist in C89.


Except it is valid "C" and many [most] C compilers do in fact support
it. In fact the only compiler I know of in productive use on 32/64 bit
boxes that doesn't is MSVC and there is a simple workaround (it has a
64-bit type just not called long long0.
See?

Not portable then.
>
So your "advice" is ignorant ranting lunatic bullshit.
WOW what nice arguments
>
>>To add 64 bit quantities you should develop and use
add64bits(a,b );
sub64bits(a,b );
mult64bits(a, b);


Or ... not use crappy toy compilers.
Exactly. Use C99.
All UNIX CC's I've seen support it. GCC supports it [since well before
C99], MSVC even supports it (indirectly).

Your comment is not well founded.

>>You should also avoid long double. This did not exist in C89.


You should avoid floats entirely if you want portable code. Many
modern platforms don't have FPUs at all.

So unless your code really needs it you shouldn't use them.

>>You should not have any array that goes beyond 32K. The size
of an integer should not be bigger than 16 bits, because that
is the minimum required by C89 if I remember correctly.


12345676UL

That's valid C89. Shut the fuck up.

This is not portable to 16 bit machines. Per standard (C99) the minimum
integer size is 16 bit only. I would be surprised that C89 was
different.
Array indecies only have to be of integer type.
Yes, and the minimum required int size is 16 bits.
Aug 1 '06 #10

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

Similar topics

1
1848
by: Lefevre | last post by:
Hello. I recently discovered that this kind of code : | struct Object | { | string f() { return string("Toto"); } | } | | int main( ... )
0
9933
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
9779
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
11114
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
10407
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
7960
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
7114
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5787
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
4605
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
4205
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.