Path: csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch
Newsgroups: comp.lang.c
Subject: Re: Safety of casting from 'long' to 'int'
Date: Wed, 13 May 2026 04:07:38 -0700
Organization: A noiseless patient Spider
Lines: 52
Message-ID: <86h5oblg91.fsf@linuxsc.com>
References: <10su8cn$am9i$1@dont-email.me> <10tls2u$39j7a$1@dont-email.me> <10tm49i$9d$1@reader1.panix.com> <10tn3so$3j8hc$1@dont-email.me> <10tnj8s$pnq$1@reader1.panix.com> <10tnmk6$3os5b$1@dont-email.me> <10tnnv1$3o0n8$2@dont-email.me> <10tntu0$3r6q3$1@dont-email.me> <865x4vrqgu.fsf@linuxsc.com> <10tqp0l$ktbv$1@dont-email.me> <861pfiq8xc.fsf@linuxsc.com> <10tt6u4$1adha$6@kst.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Date: Wed, 13 May 2026 11:07:40 +0000 (UTC)
Injection-Info: dont-email.me; logging-data="2784095"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+W+GDO6dIKjuyeszVYr9oM6i92Bf8SoBQ="; posting-host="ace8b6eaa328dcf44f89a3207699c4cb"
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:WwDpHcctofSbSJ5YJq+2wiGHeQg= sha1:nDJmi9fHjyw/sXHgNFlAZeQtSS4= sha256:4WNR89V5xdDSqlfNfP7KDvUdocVyzcBxsRCLyeMPsUY= sha1:JiFOL/5mrVymS0M1qqY892XPdHc=
Xref: csiph.com comp.lang.c:398858
Keith Thompson writes:
> Tim Rentsch writes:
> [...]
>
>> BYTE and WORD are poor choices for type names, no doubt
>> about that.
>
> [...]
>
> WORD is certainly ambiguous (unless, I suppose, it's sufficiently
> obvious from the context). But I don't have a problem with BYTE,
> or preferably byte, as a type name as long as it really is a byte.
>
> C does have a byte type; it just happens to spell it "unsigned char".
> But I don't object to something like
>
> typedef unsigned char byte;
>
> and I've used it myself.
BYTE is a poor choice for a type name because it looks like a
macro.
A lower-case version, byte, is a poor choice for a type name,
because it is both confusing and ambiguous.
Confusing, because for a very long time and for a huge segment of
the programming community, the term byte is synonymous with eight
bits, but in C that need not be true.
Ambiguous, because byte could easily mean any of three types.
The C standard library makes things worse by using 'int' for what
are basically characters, augmented with a non-character value --
EOF -- that means "something else". If byte is synonymous with
character, it might also mean 'int'.
In K&R the word "byte" is used not as a type but as a unit of
measure. The C standard defines "byte" as an addressable unit of
storage to hold any member of the basic character set -- not a
type but an amount of memory, which if anything sounds like it
might correspond to the type 'char'. In talking about character
strings, the C standard says a string ends with a byte with all
bits set to zero - another argument that 'byte' should be the
same as 'char'. It's easy to imagine an independently developed
third-party library using 'byte' to mean 'char' - more confusion
and more ambiguity. It's better to avoid the name 'byte' as a
type name altogether.
There is nothing to stop you from writing confusing or ambiguous
code. But just because you have done so doesn't make it a good
idea.