Ed Jensen said:
Don't worry about it, Martin. To be honest, I was expecting that kind
of response much sooner. It's just sort of the...personality...of
this newsgroup. Since I've been online since about 1979, I've had
ample time to marvel at this kind of fascinating emergent behavior in
online communities.
There are very few regulars here in comp.lang.c that'll admit that
writing 100% portable C code is non-trivial.
I'm one of them, however.
I think it's easy to write *very* portable code, but difficult to write
100% portable code. Consider, for example, this simple program:
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main(int argc, char **argv)
{
int rc = EXIT_SUCCESS;
unsigned long fa[UCHAR_MAX + 1] = {0};
int ch = 0;
size_t i = 0;
FILE *fp = argc > 1 ? fopen(argv[1], "rb") : NULL;
if(fp != NULL)
{
while((ch = getc(fp)) != EOF)
{
++fa[ch];
}
fclose(fp);
if(ferror(fp))
{
fputs("Input error.\n", stderr);
rc = EXIT_FAILURE;
}
else
{
for(i = 0; i < sizeof fa / sizeof fa[0]; i++)
{
if(fa
> 0)
{
printf("%lu: %lu\n", (unsigned long)i, fa);
}
}
}
}
else
{
fputs("Can't open input file.\n", stderr);
rc = EXIT_FAILURE;
}
return rc;
}
This will work (I have tested it, so I know that it will at least
compile!) on Linux. It will work on Windows. With appropriate JCL,
it'll work on a mainframe. It will work on an Atari ST or an Amiga.
It'll work on MS-DOS. I see no reason why it wouldn't work on a Cray.
It'll work on lots of platforms, in fact.
It'll even work on a Mac - or will it? If not, why not?
And on what other platforms will it not work? And for what reasons? The
code /looks/ portable - but there are more problems in the code than
are immediately obvious to the eye.
I can see - well, several, at any rate!