[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Some suggested corrections to the standards document
From: |
Paul Eggert |
Subject: |
Re: Some suggested corrections to the standards document |
Date: |
Wed, 08 Nov 2006 20:48:21 -0800 |
User-agent: |
Gnus/5.1008 (Gnus v5.10.8) Emacs/21.4 (gnu/linux) |
address@hidden (Karl Berry) writes:
> True enough. I have to shame-facedly confess that I'm not sure of the
> recommended way to write it. Introduce a char variable, like the below?
> Use a cast somehow? Paul?
What you had was the right idea, except it should use unsigned char
instead of char, to be portable to (admittedly weird) systems where
char is signed and there's integer overflow checking so an exception
is raised when storing (say) 255 into a char variable. So this is a
bit better:
int c;
while ((c = getchar ()) != EOF)
{
unsigned char u = c;
write (file_descriptor, &u, 1);
}