Keith Thompson said:
Rod Pemberton said:
[in response to Keith question]
#include <stdio.h>
#include <stdlib.h>
#define HW "Hello World!\n"
int main(void)
{
FILE *out;
char ch;
out=tmpfile(); /* ANSI wb+ */
fprintf(out,HW);
rewind(out);
while(1)
{
ch=getc(out);
if(feof(out))
break;
putchar(ch);
} /* because I could... */
exit(EXIT_SUCCESS);
}
So you print "Hello World!\n" to a binary file, then you read it back
and print each character *to a text stream". The whole rigmarole
of writing the string to a binary stream and reading it back again
accomplished, at best, exactly nothing (assuming that the binary file
isn't padded with additional null characters, which is permitted).
Exactly...
Strictly speaking, you've written a "hello world" program that
uses binary mode -- but it doesn't use binary mode to produce the
"hello world" output.
Well, you made no specification that the primary output must be made to the
console. The only specification was to use binary mode, which I did. As
far as you specified, I could've fprintf()'d "Hello World!\n" to a file and
let the user figure out how to display it.
Recall lack of specificity:
KT> You can't even write a portable "hello world" program
KT> using binary mode.
Do you have something that actually supports your claim? Can you
write a portable "hello world" program that doesn't use text mode?
Well, that wasn't my claim. It was yours. I made no claims about
_portable_ programs _without_ text mode, or even "hello world" programs for
that matter. I said _binary_ was _well_suited_ for _text_. And, it is. It
usually works better IMO. You'd want that clarified: for a specific
platform...
Almost everyone except you, apparently.
Hmm, no response to key questions...
The two points were:
A) How do you write portably when 1) even portable C code is only so
portable, 2) you cannot test the code on other difficult systems anymore,
and 3) the only way to detect many of these issues today is by compiler
warnings?
I found a way to test EBCDIC. Unfortunately, I don't have it setup. But, I
can't test on a Cray. Or, old IBM "iron". etc. So, if I've got code in
which I mistakenly treated a pointer to a struct and a pointer to a union
(or some other type) to be equivalent and if the compiler doesn't warn me
that this is non-portable, how do I determine that the code is non-portable?
B) Why should you even attempt to support a non-x86 platform today?
x86 is the dominant platform. Both the dominant x86 and modern non-x86
platforms use the same basic memory and I/O architectures that were in use
at C's creation. If fact, almost all microprocessor based platforms back to
1974 do. It's the obsolete miniframes, mainframes, and obscure hardware
platforms, non-ASCII platforms, and those that used a central processing
unit, that didn't.
But you're
advocating removing features from the C language that exist for
the purpose of enabling portable code.
What?
While there is _much_ in C that shouldn't be used for many reasons IMO, I do
not recall explicitly mentioning the _removal_ of anything. That's a
conclusion you deduced.
Would C have been better off if it only had a single file mode? I think so.
Except for boundary cases, like carriage return, linefeeds, and newlines,
the C code for text and non-text could would be of a single form or style.
And, the boundary cases would be well known and well preserved in the code -
perhaps in simple #ifdef code sections... I'd guess that if that had been
done, we might've even seen a new standardized header containing all the
relevant info, perhaps as part of "C90". That'd have been much better for
portability, don't you think?
Rod Pemberton