473,416 Members | 1,730 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

Books on developing portable C suites

Hi,

Can someone recommend a book that will teach me how to
approach C programming so that code is modularised, will compile
for different environments (such as variations of Unix and
Windows), will be robust etc.

As an example, I am developing a BSD Sockets suite which I want
to run under various Unixes, including the Zaurus version of
Linux, and also run parts of it under Windows. My thought is to
have the system calls as libraries somehow but without obscuring
the familiarity of the main code.

I want to be able to run
modules stand-alone (such as the module which converts a text
SNMP OID to ASN.1 encoding) but also use the same code from
within other modules. The ideal solution would be some sort of
dynamic linking, if it is fast enough. It also should be not
cumbersome to configure. Questions arise such as how do I locate
component modules - env var?, path?, locate with main module?
etc.

There's more to the need than that above. I don't need book on
how to use printf, pointers etc. There are hundreds of them. I
need something to go beyond coding and on to building complete
systems in C.

Hope someone can help.
Thanks,
James
Nov 13 '05 #1
13 2699
On Sat, 2 Aug 2003 12:22:08 +0100, "James Harris" <no.email.please>
wrote:
Hi,

Can someone recommend a book that will teach me how to
approach C programming so that code is modularised, will compile
for different environments (such as variations of Unix and
Windows), will be robust etc.
<snip>


A search for Title="Portable C" on amazon yielded the following;
probably can find more with a little digging and some more targeted
searches perhaps on Google.

Portable C (Prentice Hall Software Series)
by Henry Rabinowitz, Chaim Schaap (Contributor)
Out of Print--Limited Availability

Portable C and Unix System Programming (Prentice-Hall Software Series)
by J.E. Laping, J. E. Lapin
Out of Print--Limited Availability
Portable C Software
by Mark R. Horton
Out of Print--Limited Availability

Developing C Language Portable System Call Libraries/Book and Disk
by Matt Weisfeld
Out of Print--Limited Availability

Information Technology-Portable Operating System Interface (Posix):
System Application Program Interface (Api) (C Language)
by IEEE (Paperback - January 1997)

Solutions to Systems Portability in C and C++: Your Guide to Writing
Truly Portable Applications/Book and Disk
by John L. Bradberry, John E. Swanke
Out of Print--Limited Availability

Portable C
(Paperback - February 1990)
Special Order, no author given
Nov 13 '05 #2

"James Harris" <no.email.please> wrote in message
news:3f*********************@lovejoy.zen.co.uk...
Hi,

Can someone recommend a book that will teach me how to
approach C programming so that code is modularised, will compile
for different environments (such as variations of Unix and
Windows), will be robust etc.

As an example, I am developing a BSD Sockets suite which I want
to run under various Unixes, including the Zaurus version of
Linux, and also run parts of it under Windows. My thought is to
have the system calls as libraries somehow but without obscuring
the familiarity of the main code.

I want to be able to run
modules stand-alone (such as the module which converts a text
SNMP OID to ASN.1 encoding) but also use the same code from
within other modules. The ideal solution would be some sort of
dynamic linking, if it is fast enough. It also should be not
cumbersome to configure. Questions arise such as how do I locate
component modules - env var?, path?, locate with main module?
etc.

There's more to the need than that above. I don't need book on
how to use printf, pointers etc. There are hundreds of them. I
need something to go beyond coding and on to building complete
systems in C.

Hope someone can help.
Thanks,
James


Hi James,
Unfortunately, programming 100% portable code ties you down to what the
ISO/IEC standard says, which does not include support for internet sockets.
I do not think buying a book on the topic (if there are any) is well-worth
it. You just need a few pointers, and lots of documentation. I suggest you
purchase a copy of the standard (only $18 USD in PDF format, see
www.iso.org.) That will give you *what* is portable and what not.

For the non-standard libraries you use such as Internet sockets, you can
build your code in such a #ifdef manner that it will compile without any
modification on all platforms, as follows:

#ifdef _WIN32
#include <winsock2.h>
#else
#include <net/socket.h> /* have no idea what the headers are for unix's,
but they aren't the same */
#endif

Secondly, you can use macros to hide the system-specific function calls and
other stuff too.

This may sound like a lot of work, but it's totally possible to do in a fair
amount of time.
If you need help on more specific questions on the same topic, don't be shy
to ask again to the group. You can also refer to portable libraries' source
code to see how they do it.
Nov 13 '05 #3
Oh one more thing, it depends on the compilers you use.
As you know, most unix's use gcc which was ported to windows (-ish) and may
lessen your work for a few things

I beleive its name is Mingw, but I could be wrong.

"Eric Bernard" <ew***@sympatico.ca> wrote in message
news:nB********************@news20.bellglobal.com. ..

"James Harris" <no.email.please> wrote in message
news:3f*********************@lovejoy.zen.co.uk...
Hi,

Can someone recommend a book that will teach me how to
approach C programming so that code is modularised, will compile
for different environments (such as variations of Unix and
Windows), will be robust etc.

As an example, I am developing a BSD Sockets suite which I want
to run under various Unixes, including the Zaurus version of
Linux, and also run parts of it under Windows. My thought is to
have the system calls as libraries somehow but without obscuring
the familiarity of the main code.

I want to be able to run
modules stand-alone (such as the module which converts a text
SNMP OID to ASN.1 encoding) but also use the same code from
within other modules. The ideal solution would be some sort of
dynamic linking, if it is fast enough. It also should be not
cumbersome to configure. Questions arise such as how do I locate
component modules - env var?, path?, locate with main module?
etc.

There's more to the need than that above. I don't need book on
how to use printf, pointers etc. There are hundreds of them. I
need something to go beyond coding and on to building complete
systems in C.

Hope someone can help.
Thanks,
James
Hi James,
Unfortunately, programming 100% portable code ties you down to what

the ISO/IEC standard says, which does not include support for internet sockets. I do not think buying a book on the topic (if there are any) is well-worth
it. You just need a few pointers, and lots of documentation. I suggest you
purchase a copy of the standard (only $18 USD in PDF format, see
www.iso.org.) That will give you *what* is portable and what not.

For the non-standard libraries you use such as Internet sockets, you can
build your code in such a #ifdef manner that it will compile without any
modification on all platforms, as follows:

#ifdef _WIN32
#include <winsock2.h>
#else
#include <net/socket.h> /* have no idea what the headers are for unix's, but they aren't the same */
#endif

Secondly, you can use macros to hide the system-specific function calls and other stuff too.

This may sound like a lot of work, but it's totally possible to do in a fair amount of time.
If you need help on more specific questions on the same topic, don't be shy to ask again to the group. You can also refer to portable libraries' source code to see how they do it.

Nov 13 '05 #4
In article <3f*********************@lovejoy.zen.co.uk>, "James Harris"
<no.email.please> says...
Can someone recommend a book that will teach me how to
approach C programming so that code is modularised,


One of the few books that seems to focus on coding for libraries
and reuse is:

"C Interfaces and Implementations, Techniques for Creating Reusable
Software", David R. Hanson, Addison-Wesley

It does cover a lot of the issues involved, although you may find
that you don't agree with everything said. It primarily focuses on
ADT design, interfaces, and sample implementations of a number of
well-known data structures using the author's method.

Nov 13 '05 #5
[Cross-posted to far too many places. Followups set to comp.lang.c]

"James Harris" <no.email.please> wrote:
Conditional compilation and macros is the kind of thing I had in
mind. I would put any conditional parts in libraries in
preference to the main code. That presents problems to me also.
For example, good practice regarding where to place those
libraries. I currently use

#include "../libs/lib1.h"

or the like. That expects the libraries to be in a sibling
directory. Is that good or is there a better practice?


Well, it assumes that you're using MS-DOS, Unix, or some derivative thereof.
Not all filesystems use the familiar Unix pathname syntax. If you really
are aiming for "portable", this isn't the strategy you're looking for.

Some people go the #ifdef route. I prefer the "these are the source files
that need to be rewritten for each new platform" route. The trick is to
keep their number and size to a minimum.

<snip>

--
Richard Heathfield : bi****@eton.powernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
Nov 13 '05 #6
Eric Bernard wrote:
Oh one more thing, it depends on the compilers you use.
As you know, most unix's use gcc which was ported to windows (-ish) and may
lessen your work for a few things


Actually compiler-specific extensions are rarely necessary,
especially when his stated goal was source portability.
The main thing he needs to tackle is the provision of
library (API) support across different platforms, not the
base language. There are multi-platform APIs for some
facilities (including sockets), but not for everything.

Another approach is to build the application around a
common operating environment (such as Inferno) and then
worry only about porting the environment, not the apps.

Nov 13 '05 #7
James Harris wrote:
For example, good practice regarding where to place those
libraries. I currently use
#include "../libs/lib1.h"
or the like. That expects the libraries to be in a sibling
directory. Is that good or is there a better practice?


There is no really good *guaranteed portable* solution.
The usual practice is to #include "lib1.h" and then set
some include-path variable in the compilation environment,
e.g. in a "project" configuration file or a "makefile" to
the right place for the particular installation. All the
platforms I work with these days support something along
those lines.

Nov 13 '05 #8
"Eric Bernard" <ew***@sympatico.ca> wrote in message news:<nB********************@news20.bellglobal.com >...
....
Hi James,
Unfortunately, programming 100% portable code ties you down to what the
ISO/IEC standard says, which does not include support for internet sockets.
It doesn't include a lot of things; sockets are just the beginning.
I do not think buying a book on the topic (if there are any) is well-worth
it. You just need a few pointers, and lots of documentation. I suggest you
purchase a copy of the standard (only $18 USD in PDF format, see
www.iso.org.) That will give you *what* is portable and what not.
Not really. The standard specifies precisely what you can count on
portably, but you have to be very familiar with the standard to
realize all of the implications of what it doesn't say. What most
programmers need is a book which actually explains those implications.
More important, it needs to explain what should be done about them.

For example, I have some code which is conceptually similar to the
following:

/* #defines NUM_ENTRIES, fun1() */
#include "my_header.h"

/* Third party library header. Contains a typedef for PGSt_integer. */
#include "PGS_types.h"

void func2(PGSt_integer array[NUM_ENTRIES])
{
long larr[NUM_ENTRIES];
int i;
for(i=0; i<NUM_ENTRIES; i++)
larr(i) = (long)array[i];
fun1(larr);
for(i=0; i<NUM_ENTRIES; i++)
array[i] = (PGSt_integer)larr[i];
}

If you look at PGS_types.h, you'll find that PGSt_integer is a typedef
for 'long int'. Therefore, why did I bother with the for loops? Why
not simply call fun1(array)? The reason is more a matter of social
dynamics than of the standard: the fact that PGSt_integer is a typedef
implies that it might be changed at some time in the future, or even
on a different platform (the installation script for this particular
third party library installs different versions of the header files on
different platforms, so you can't even figure out all the
possibilities by following the #if statements in the header).

Since the typedef makes it possible for me to write code in a way that
will work no matter what size integer they use, the fact that they've
bothered to define a typedef obligates me to write my code that way,
at least if I want it to be portable.
For the non-standard libraries you use such as Internet sockets, you can
build your code in such a #ifdef manner that it will compile without any
modification on all platforms, as follows:

#ifdef _WIN32
#include <winsock2.h>
#else
#include <net/socket.h> /* have no idea what the headers are for unix's,
but they aren't the same */
#endif


That will NOT work on all platforms; only on Windows and Unix-like
platforms. The programming world is a lot bigger than that.
Nov 13 '05 #9

"James Harris" <no.email.please> wrote in message

Can someone recommend a book that will teach me how to
approach C programming so that code is modularised, will compile
for different environments (such as variations of Unix and
Windows), will be robust etc.

Buy a copy of C Unleashed. One of the authors, Mr Heathfield, is a reg here
and will be more than happy to answer any queries raised :-)
Nov 13 '05 #10
Eric Bernard wrote:
For the non-standard libraries you use such as Internet sockets, you can
build your code in such a #ifdef manner that it will compile without any
modification on all platforms, as follows:

#ifdef _WIN32


For a tentative list of pre-defined compiler macros see

http://predef.sourceforge.net/
Nov 13 '05 #11
>>Conditional compilation and macros is the kind of thing I had in
mind. I would put any conditional parts in libraries in
preference to the main code. That presents problems to me also.
For example, good practice regarding where to place those
libraries. I currently use

#include "../libs/lib1.h"

or the like. That expects the libraries to be in a sibling
directory. Is that good or is there a better practice?

Well, it assumes that you're using MS-DOS, Unix, or some derivative thereof.
Not all filesystems use the familiar Unix pathname syntax. If you really
are aiming for "portable", this isn't the strategy you're looking for.

Some people go the #ifdef route. I prefer the "these are the source files
that need to be rewritten for each new platform" route. The trick is to
keep their number and size to a minimum.


A better strategy would be to always just use:
#include "lib1.h"
and then explicitly specify the include path directories in the
compiler invocation.
This requires disciplined programming to ensure you don't end up
including the wrong file because of duplicate .h filenames in different
directories (in big projects with multiple coders, this is a real
concern).
The standard doesn't specify either the syntax of include
pathnames, or the search path semantics for included files (there are
some very weak assertions regarding the differences between <> and ""
style inclusions, but they amount to nothing much that is usable). It is
considered out of scope, even though, in reality, the UNIX style names
are supported by compilers even on platforms with a different path name
syntax.

Ajoy.

Nov 13 '05 #12
Ajoy K Thamattoor wrote:
Conditional compilation and macros is the kind of thing I had in
mind. I would put any conditional parts in libraries in
preference to the main code. That presents problems to me also.
For example, good practice regarding where to place those
libraries. I currently use

#include "../libs/lib1.h"

or the like. That expects the libraries to be in a sibling
directory. Is that good or is there a better practice?

Well, it assumes that you're using MS-DOS, Unix, or some derivative
thereof. Not all filesystems use the familiar Unix pathname syntax. If
you really are aiming for "portable", this isn't the strategy you're
looking for.

Some people go the #ifdef route. I prefer the "these are the source files
that need to be rewritten for each new platform" route. The trick is to
keep their number and size to a minimum.


A better strategy would be to always just use:
#include "lib1.h"
and then explicitly specify the include path directories in the
compiler invocation.


I agree that that's a decent strategy, but it doesn't actually conflict with
anything I said, so I'm not sure why you say it's "better".
This requires disciplined programming to ensure you don't end up
including the wrong file because of duplicate .h filenames in different
directories (in big projects with multiple coders, this is a real
concern).
As you say, that's a discipline issue.
The standard doesn't specify either the syntax of include
pathnames, or the search path semantics for included files (there are
some very weak assertions regarding the differences between <> and ""
style inclusions, but they amount to nothing much that is usable). It is
considered out of scope, even though, in reality, the UNIX style names
are supported by compilers even on platforms with a different path name
syntax.


Are you absolutely sure that Unix-style names are supported on, say, OS390?

--
Richard Heathfield : bi****@eton.powernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
Nov 13 '05 #13
Much thanks to all who responded, though not many had any book
suggestions(!) I've ordered the following books,

The C Programming Language (Prentice Hall Software Series)
The Practice of Programming (APC)
Safer C: Developing Software for High-integrity and
Safety-critical Systems
C Interfaces and Implementations: Techniques for Creating
Reusable Software
Portable C (Prentice Hall Software Series) [Paperback] by
Rabinowitz, Henry (second hand)
Code Complete: A Practical Handbook of Software Construction
C Unleashed

As a general note from looking for books on C the truth seems to
be that many that I would have preferred were no longer
available. As the Portable C books that Sam found illustrate
these are no longer in print. There seemed to be a few C++ books
of the kind I want but at the moment I'll stick with C.

Maybe C++ another time, once my bank manager is speaking to me
again....<g>

Cheers,
James

"James Harris" <no.email.please> wrote in message
news:3f*********************@lovejoy.zen.co.uk...
Hi,

Can someone recommend a book that will teach me how to
approach C programming so that code is modularised, will compile
for different environments (such as variations of Unix and
Windows), will be robust etc.

As an example, I am developing a BSD Sockets suite which I want
to run under various Unixes, including the Zaurus version of
Linux, and also run parts of it under Windows. My thought is to
have the system calls as libraries somehow but without obscuring
the familiarity of the main code.

I want to be able to run
modules stand-alone (such as the module which converts a text
SNMP OID to ASN.1 encoding) but also use the same code from
within other modules. The ideal solution would be some sort of
dynamic linking, if it is fast enough. It also should be not
cumbersome to configure. Questions arise such as how do I locate
component modules - env var?, path?, locate with main module?
etc.

There's more to the need than that above. I don't need book on
how to use printf, pointers etc. There are hundreds of them. I
need something to go beyond coding and on to building complete
systems in C.

Hope someone can help.
Thanks,
James

Nov 13 '05 #14

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

Similar topics

9
by: Bozo Schmozo | last post by:
Can someone please recommend some good books on developing web sites (pretty much from scratch) running PHP and the necessary/usual components required, such as MySQL, Apache and etc? As well,...
4
by: Bozo Schmozo | last post by:
Can someone please recommend some good books on developing web sites (pretty much from scratch) using ASP and the necessary/usual components required, such as XML, C# and etc.? As well, if I...
0
by: Fergus Henderson | last post by:
"James Harris" <no.email.please> writes: >Can someone recommend a book that will teach me how to >approach C programming so that code is modularised, will compile >for different environments...
9
by: Shamli | last post by:
Hi, I have a C program, and i looking to develop a simple GUI for this program. i want to use something that is platform independent (portable) and easy to learn. Any suggestion is highly...
17
by: Venkatesh | last post by:
Hi All I am a newbie to C# .I am currently developing windows application.Can anyone suggest good books or links for developing Windows Applications using C#.
7
by: boostngti via DotNetMonster.com | last post by:
I have 4 years of programing exp. with Coldfusion, and I am begining to learn ASP.NET C# and was wondering if some people could suggest some good books. I went to Barnes & Noble the other day...
131
by: pemo | last post by:
Is C really portable? And, apologies, but this is possibly a little OT? In c.l.c we often see 'not portable' comments, but I wonder just how portable C apps really are. I don't write...
8
by: Rajeev | last post by:
Please anybody from the group please give me the names of BEST C books. Thanking you. Rajeev
2
by: youpak2000 | last post by:
What you can't find in programing text books Professional software development needs more knowledge than language syntax, OOP, styles, etc. There are many things which people usually learn by...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.