Sujet : Re: VMS
De : invalid (at) *nospam* invalid.invalid (Richard Kettlewell)
Groupes : comp.os.linux.miscDate : 30. Jun 2025, 08:56:12
Autres entêtes
Organisation : terraraq NNTP server
Message-ID : <wwvplelu0gz.fsf@LkoBDZeT.terraraq.uk>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
User-Agent : Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
c186282 <
c186282@nnada.net> writes:
On 6/29/25 3:18 AM, Richard Kettlewell wrote:
c186282 <c186282@nnada.net> writes:
On 6/28/25 3:52 AM, Richard Kettlewell wrote:
c186282 <c186282@nnada.net> writes:
On 6/27/25 1:40 PM, rbowman wrote:
On Fri, 27 Jun 2025 13:24:06 -0400, c186282 wrote:
Some of us are old enough to remember when CPUs were not always
4/8/16/32/64 ... plus even now they've added a lot of new types like
128-bit ints. Simply ASSUMING an int is 16 bits is 'usually safe'
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
but not necessarily 'best practice' and limits future (or past)
compatibility. 'C' lets you fly free ... but that CAN be straight
into a window pane
Assuming an int is 16 bits is not a good idea. I wouldn't even assume
a short is 16 bits
(Apart from c186282 who for some reason thinks it’s “usually safe”,
nobody here is making any such assumption about int.)
>
Eh ? I've been saying no such thing - instead recommending
using sizeof() kind of religiously. I remember processors
with odd word sizes - and assume there may be more in
the future for whatever reasons.
You wrote it above. Underlined to help you find it again.
>
>
Mysteriously MISSING THE OTHER HALF OF THE LINE :-)
It’s quote above in full, and the bit I didn’t underline doesn’t change
your claim that it’s “usually safe”.
If you disagree with that then argue with your past self, not me, I’m
just quoting what you wrote.
The thread is not about the size of int, etc. It’s about the specific
case of sizeof(char) in C, and that is always 1.
>
CHAR is ONE BYTE of however many bits, but beyond that ..........
>
Use sizeof() ...
>
One flaw of sizeof() is that it reports in BYTES ... so,
for example, how many BITS is that ?
I don’t see a flaw there. If you want to know the number of bytes
(in
the C sense) then that’s what sizeof does. If you want to know the
number of bits, multiply by CHAR_BIT. If you already have a number of
bytes, and you want a number of bytes, no need to multiply by anything
at all.
>
That'll work fine.
>
Not sure EVERY compiler has CHAR_BIT however ...
It was introduced in 1989 as a requirement for all C implementations,
anything that doesn’t have it doesn’t really have a good claim to be C
any more.
-- https://www.greenend.org.uk/rjk/